ray Posted January 16, 2008 Report 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
andrisp Posted January 16, 2008 Report 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
Paulinjsh Posted January 16, 2008 Report 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
andrisp Posted January 16, 2008 Report 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
ray Posted January 16, 2008 Author Report 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);
andrisp Posted January 16, 2008 Report Posted January 16, 2008 Tāpēc, ka droši vien tiek izmantots tikai \n nevis \r\n.
john.brown Posted January 16, 2008 Report Posted January 16, 2008 str_replace(array("\r","\n"),array('', ' '), $string);
Recommended Posts