PHPmotion line break problems

Please note this post was written for V2 and older it most likely will not work for more recent versions of PHPmotion. Make changes at your own risk and always keep backups!

Many people on the forum post about having <br/> appearing in descriptions, comments, etc.. well I had this problem too on a clients website so I fixed it. And I thought I might as well share it with all other webmasters having problems out there.

This solution is probably only best suited to those with quite a few videos already uploaded as it applies the changes to any video. If you are working on a new site it may be simpler to clean the tags on upload.

First step, open up your favorite text editor, create a blank file and name it functions.php. Then copy/paste the following code into it:


function clean_tags($field,&amp;amp;amp;$value)
{
/**
Remove unwanted breaks, etc..
**/
$clean = strip_tags(str_replace(array('<br>','<br />','<br/>',"\r\n"),'',$value));
$value = sentence_spacing($clean);
}

function sentence_spacing($the_string)
{
/**
When breaks are removed it can squish all together, add spaces in correct places.
May or may not be the same for all languages.
**/
$patterns = array("/!/","/\s,/","/\?/","/\./");

$replacement = array("! ",", ","? ",". ");

$the_string = preg_replace($patterns,$replacement,$the_string);

$the_string = str_replace('  ',' ',$the_string);

return $the_string;
}

Basically the first function clean_tags does… you guessed it remove unwanted tags and line breaks from the string. Whilst the sentence_spacing function helps make sure that it doesn’t all turn into one big string of words stuck together. By using the preg_replace function it adds an extra space if needed after characters like: ?, !, ., etc..

Anyway once that file is created and saved upload it into your classes/ folder. Now in classes/config.inc.php add the following line to make the functions available to the script:


require_once('functions.php');

This can be placed pretty much anywhere within the php tags. Now upload that file. This is where you get to start using the cool new functions we’ve just made. Open up the template file of the page which is displaying the problem and find for example the following (from inner_index.htm):

<!--[blkfeatured.description;block=div;ope=max:45;comm]-->

Now change it to this:

<!--[blkfeatured.description;block=div;ope=max:45;onformat=clean_tags;comm]-->

Now if all went well after uploading the template all <br/> problems should have disappeared from that block. :) You just need to add this to any other place you start seeing this problem pop up.

Did this help or didn’t it work? Please leave a comment below or post in the forum to let me know!

5 Responses to “PHPmotion line break problems”


  1. 1 Peter Skuse

    Ben,

    Haven’t completed the above mod yet yet, but just to let you know that when I click on the ‘copy to clipboard’ link above and paste it into Notepad, the # turn into what looks like a rectangle (The character won’t copy and paste, so can’t show it).

    But if I copy and paste using mouse right-click, the code pastes fine.

    Pete

  2. 2 Peter Skuse

    Ben,

    Not really sure what “..can be placed pretty much anywhere within the tags..” means.

    classes/config.inc.php seems to have a lot of specific headers in the code and even a “do not edit this” command, so unsure where to put it.

    Can you give me an exact location please?

    Pete

  3. 3 Ben

    Sorry it should read between the < ?php & ?> tags, I’ll update the post.

    It’s probably easiest to add the code right at the end before the ?> tag on it’s own line.

  4. 4 J

    After I did this it broke the siteadmin. It took it out and site admin worked again. Put it back in…broken. Any thoughts?

  5. 5 Ben

    Hi J, I’m not sure why the changes would have broken the admin area. But this post was written a while back so it may not work on newer versions of PHPmotion.

Leave a Reply