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; } ?> Quote Link to comment 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); } ?> Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.