Jump to content

creating a <br> after so many chars


ccrevcypsys

Recommended Posts

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

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);
}
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.