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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.