Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] jak usunac 2wie spacje w tekscie
Forum PHP.pl > Forum > PHP
AndyPSV
mam takie cos, jak usunac 2wie spacje w tekscie - jesli te 2 spacje sa pomiedzy <td*></td> (chodzi mi o kazde <td> w przedstawionym przykladzie):

  1. 8 =>
  2. array (
  3. 0 => '<tr class=\'xl41\' height=\'15\' style=\'height:11.25pt\'> <td height=\'15\' class=\'xl47\' align=\'right\' style=\'height:11.25pt\' x:num=\'\'>12</td> <td class=\'xl41\'>02</td> <td class=\'xl41\'>01</td> <td class=\'xl41\'>01</td> <td class=\'xl41\'>Bolesławiec</td> <td class=\'xl41\'>2</td> <td class=\'xl41\'>00003</td> <td class=\'xl41\'>001</td> <td class=\'xl41\'>Prywatna Szkoła Podstawowa \'Oxpress\' w Bolesławcu</td> <td class=\'xl41\'>0</td> <td class=\'xl41\'>Tyrankiewiczów</td> <td class=\'xl41\'>22</td> <td class=\'xl41\'>59-700</td> <td class=\'xl41\'>Bolesławiec</td> <td class=\'xl41\'>0757325055</td> <td class=\'xl41\'>0757325845</td> <td class=\'xl41\'>0</td> <td class=\'xl41\'>002</td> <td class=\'xl41\'>001</td> <td class=\'xl41\'>100</td> <td class=\'xl41\'>0100</td> <td class=\'xl41\'>0033</td> <td class=\'xl41\'>Dariusz Tyrakowski</td> <td class=\'xl41\'>10</td> <td class=\'xl41\'>61</td> <td class=\'xl41\'>01</td> <td class=\'xl41\'>0001</td> <td class=\'xl41\'>Gmina Bolesławiec (miejska)</td> <td class=\'xl41\'>02</td> <td class=\'xl41\'>01</td> <td class=\'xl41\'>01</td> <td class=\'xl41\'>23022700400028</td> <td class=\'xl41\'>&nbsp;</td> <td class=\'xl41\'>&nbsp;</td> <td class=\'xl55\'>&nbsp;</td> <td class=\'xl41\'>&nbsp;</td> <td class=\'xl41\'>&nbsp;</td> <td class=\'xl55\'>&nbsp;</td> <td class=\'xl41\'>&nbsp;</td> <td class=\'xl41\'>&nbsp;</td> <td class=\'xl41\'>&nbsp;</td> <td class=\'xl41\'>&nbsp;</td>',
  4. ),
magiczny_piesek
http://php.net/manual/en/function.strpos.php
http://pl.php.net/manual/en/function.substr.php

Tniesz string na kawałki, jednocześnie gubiąc zbędne kawałki, później łączysz w całość.
AndyPSV
a co mi da strpos? albo substr przy tym?
myslalem o explode(), ale chce to zalatwic w ten sposob, ze

====

juz zrobilem to:

  1. $_r = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/","",$_r); $_r = preg_replace("/\n\r|\r\n|\n|\r|\t| {2}/",' ',$_r);
  2.  
  3. $r = explode('<td class="xl50" style="border-top:none;border-left:none" x:num="">38</td>',$_r); $r = explode('<td class="xl48">&nbsp;</td>',$r[1]); $r = explode('<!--[endif]-->',$r[4]); $r = explode('</tr>',$r[0]);
  4. unset($r[0]); array_pop($r); foreach($r as $k) {
  5. $k = utf8pl($k); $k = str_replace(' '," ",$k); $k = str_replace('"',"'",$k); $k = str_replace('> <',NL,trim($k)); $k = strip_tags($k);
  6.  
  7. $op[] = explode(NL,trim($k));
  8. }
  9.  
magiczny_piesek
Jak pomyślisz, to rozwiąrze twój roblem, chodź faktycznie, lepiej użyć str_replace, ale nie tak jak Ty to zrobiłes.

Wyrażeń regularnych tam gdzie można lepiej unikać ze względu na wydajność.


W twoim przypadku, chyba takie coś dało by radę:
$str = str_replace ( '</td> <td' , '</td><td' , $str);
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.