ray Posted January 16, 2008 Report Share Posted January 16, 2008 (edited) nesaprotu kāpēc man textarea rādās, ka ir 2 enter pēc šāda ieraksta apstrādes koda: preg_replace("/<br\\s*?\/??>/i", "\r\n", $string); Edited January 16, 2008 by ray Link to comment Share on other sites More sharing options...
andrisp Posted January 16, 2008 Report Share Posted January 16, 2008 Vispār jau tev tas regexps tāds dīvains (tas nestrādā). Man ar šādu viss notiek normāli: /<br\s*?\/{0,1}>/i Link to comment Share on other sites More sharing options...
Paulinjsh Posted January 16, 2008 Report Share Posted January 16, 2008 (edited) atkal ar lielgabalu :) $blah = str_replace("\r\n", '<br />', $blah); vēl perfomance uzlabot var, ja veic pirms tam pārbaudi: if (strpos($blah, "\r\n") !== false) { $blah = str_replace("\r\n", '<br />', $blah); } Edited January 16, 2008 by Paulinjsh Link to comment Share on other sites More sharing options...
andrisp Posted January 16, 2008 Report Share Posted January 16, 2008 (edited) Paulinjs, tu sajauci virzienus. ;) Bet vispār tavs variants ir ideāls tikai tad, ja vienmēr būs "<br />". Bet ja nu ir "<br>" vai "<br/>", vai "<br[vairākas atstarpes]/>" ? Edited January 16, 2008 by andrisp Link to comment Share on other sites More sharing options...
ray Posted January 16, 2008 Author Report Share Posted January 16, 2008 sapratu kas par kļūdu, man db saglabājies arī enter, ne tikai <br /> tikai man nesanāk viņu dabūt arā ar šo str_replace("\r\n", " ", $string); Link to comment Share on other sites More sharing options...
andrisp Posted January 16, 2008 Report Share Posted January 16, 2008 Tāpēc, ka droši vien tiek izmantots tikai \n nevis \r\n. Link to comment Share on other sites More sharing options...
Paulinjsh Posted January 16, 2008 Report Share Posted January 16, 2008 ok, ne tur aizšāvu :) Link to comment Share on other sites More sharing options...
john.brown Posted January 16, 2008 Report Share Posted January 16, 2008 str_replace(array("\r","\n"),array('', ' '), $string); Link to comment Share on other sites More sharing options...
Recommended Posts