Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Dzielenie tekstu na dwie równe części
arzach
post
Post #1





Grupa: Zarejestrowani
Postów: 332
Pomógł: 6
Dołączył: 27.11.2008

Ostrzeżenie: (0%)
-----


Witam mam próbuje podzielić tekst na dwie równe części i między ten tekst wstawić reklamę

Zrobiłem ale to nie jest najlepsze rozwiązanie ponieważ dzieli źle wyrazy np. jak mam test to wychodzi t est itp. czy można to zrobić lepiej ?

  1. $news = "TEST TEST TEST TESTTTTTTT TES TSTST";
  2.  
  3. $ceil = ceil(strlen($news) / 2);
  4.  
  5. $news = str_split($news, $ceil);
  6.  
  7.  
  8. $reklama = "<script type=\"text/javascript\"><!--
  9. google_ad_client = \"pub-3995387288904286\";
  10. /* 160x90, utworzono 10-09-24 */
  11. google_ad_slot = \"1776115406\";
  12. google_ad_width = 160;
  13. google_ad_height = 90;
  14. //-->
  15. </script>
  16. <script type=\"text/javascript\"
  17. src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
  18. </script>";
  19.  
  20.  
  21.  
  22. $news = $news[0]."<div style='text-align:center;'></br>".$reklama."<div></br>".$news[1];


Ten post edytował arzach 5.10.2010, 19:17:46
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Wicepsik
post
Post #2





Grupa: Zarejestrowani
Postów: 1 575
Pomógł: 299
Dołączył: 26.03.2009

Ostrzeżenie: (20%)
X----


  1. $news = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eu lorem nisl, nec pulvinar enim. Nulla lectus libero, consectetur at viverra pellentesque, ullamcorper in urna. Curabitur dolor leo, commodo in aliquet ut, aliquet in tellus. Donec commodo odio at eros venenatis pellentesque. Aenean id tellus tellus. Nam vehicula, eros tristique tristique laoreet, dui felis condimentum tellus, in vestibulum ante felis ut metus. Ut arcu purus, volutpat vel ornare ut, tincidunt eget nisl. Suspendisse et diam sed arcu tempus varius. Nullam nec justo et felis euismod consectetur vel non nisi. Integer nulla metus, ullamcorper et viverra at, feugiat eget erat. Nulla. ";
  2.  
  3. $ilosc = strlen($news);
  4. $polowa = ceil($ilosc/2);
  5. $news = wordwrap($news, $polowa, "<br />");
  6. echo $news;
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 01:55