ccrevcypsys Posted June 9, 2008 Share Posted June 9, 2008 Hello i am turning a cfm file into a php file and it is just about done. all that i need 2 do is figure out how to change this function to make it work for php. what it does is after a certain ammount of chars it will put in a <br> so that it is not all clumped 2 gather. can someone help me figure this out?? PLZ Heres the cold fusion script. <CFSCRIPT> function formatME(myTest) { myTest = preg_replace(myTest,chr(9)," ","ALL"); myTest = Replace(myTest,chr(13),"<br />","ALL"); return myTest; } </CFSCRIPT> Here is what i have made it into (doesnt work...) <?php function formatME($myTest) { $myTests = str_replace(" ",chr(9),$myTest); $myTests = str_replace("<br />",chr(13),$myTest); return $myTests; } ?> Link to comment https://forums.phpfreaks.com/topic/109474-creating-a-after-so-many-chars/ Share on other sites More sharing options...
Psycho Posted June 9, 2008 Share Posted June 9, 2008 I don't understand the scripts you have above as they don't correspond to what yousay you want to do. The following function will insert an HTML break tag at every 50 characters: <?php function formatME($input) { return preg_replace('/(.{50})/', '$1<br />', $input); } ?> Link to comment https://forums.phpfreaks.com/topic/109474-creating-a-after-so-many-chars/#findComment-561580 Share on other sites More sharing options...
DarkWater Posted June 9, 2008 Share Posted June 9, 2008 Better than that is: wordwrap($str, 50, "<br />"); http://us3.php.net/wordwrap Link to comment https://forums.phpfreaks.com/topic/109474-creating-a-after-so-many-chars/#findComment-561582 Share on other sites More sharing options...
Psycho Posted June 9, 2008 Share Posted June 9, 2008 Better than that is: wordwrap($str, 50, "<br />"); http://us3.php.net/wordwrap Showoff! RegEx is geekier. Link to comment https://forums.phpfreaks.com/topic/109474-creating-a-after-so-many-chars/#findComment-561595 Share on other sites More sharing options...
DarkWater Posted June 9, 2008 Share Posted June 9, 2008 Better than that is: wordwrap($str, 50, "<br />"); http://us3.php.net/wordwrap Showoff! RegEx is geekier. For the TS, I meant: wordrwap($str, 50, "<br />"); The post made the line break into an actual line break. =/ *Sighs* @mjdamato: I can do regexes. D: But this is faster, lol. Link to comment https://forums.phpfreaks.com/topic/109474-creating-a-after-so-many-chars/#findComment-561600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.