Page 1 of 1

PHP condition into the begining of a text!

Posted: Fri Sep 24, 2010 8:52 am
by xamonix
Hi everyone!
I'm trying to find a php code to manage this:

I want to add a line break tag

Code: Select all

<br />
into the first line of a text block. My goal is to add the line break tag if the text block doesn't have any, if there is already a <br /> tag in the beginning of the text then do nothing.

Is it possible to do? Can anyone help me on this?
Thank you.

Re: PHP condition into the begining of a text!

Posted: Fri Sep 24, 2010 9:59 am
by Gungneer
I'm not 100% sure on what you mean, but you could try something like this...

Code: Select all

$str = str_ireplace('<br />',"<br />\n",$str);

Re: PHP condition into the begining of a text!

Posted: Fri Sep 24, 2010 12:06 pm
by John Cartwright
Post what you've got so far, and we can start from there.

Re: PHP condition into the begining of a text!

Posted: Fri Sep 24, 2010 2:32 pm
by xamonix
Well the scenario is this:

I've got a website were some people (editors) can publish articles. They have to write an introtext followed by the full text. For design purposes the intro text should be separated by a blank line (line break) from the full text. Some editors put the line break at the begining of the full text toacomplish that, but others don't. So I was trying to manage that trough PHP code. The condition would be: If the line break is already in the text then do nothing, if not then add a line break at the beginning of the full text.

The PHP code I have to manage the introtext and the full text is this:

Code: Select all

// show/hides the intro text
    if ( $params->get('introtext'  ) ) {
        
        $intro = $row-> introtext;
        $row->text = "<span class='intro'>".$intro."</span>". ( $params->get( 'intro_only' ) ? '' : chr(13) . chr(13) . $row->fulltext);
    } else {
        $row->text = $row->fulltext;
    }
Hope you understand my point!