Page 1 of 1

replace occurance of "<br />" with ""

Posted: Wed Sep 10, 2008 6:30 am
by hemanshurpatel
Hello friends,
I am not that novice with php, but this thing is messing with me since last few days

What my requirement is that i ahve aparagraph of text, in those there are "<br />" terms appears two times simultaneously.
So i have to remove those term with one
let me give you an example
Well again, solve your first problem.

It depends on what is meant by "extract" but good practice for solving problem two, would be to copy the substring from str to interesting_part for problem one, and then physically moving the rest of the string to make room for the new word in problem two.

When you've created sufficient space, go ahead and overwrite the old word by copying the new one in.
when i see source of above text it gives some text as below
xxxxxxxxxxxxxx<br />
<br />
xxxxxxxxxxxx

i want to replace those two occurances with one
i have use str_replcae function but doesnt help

can anyone help me in solving this, what can be the silly mistake i am doing?


Regards
Hemanshu

http://tutorialsforu.info

Re: replace occurance of "<br />" with ""

Posted: Wed Sep 10, 2008 7:14 am
by hemanshurpatel
hi there
i was trying mean while

when i used

Code: Select all

$final = preg_replace("/<br \/>/","",$final);
my all occurences of <br /> is been removed, but i dont wnat that.
I want is that when <br /> comes two times, one: end of line 1 and two: beginning of line 2, then remove once occurrence of that

can anyone help in preg_replac pattern for searching. i m not getting how those patters are generated, i agev googled a bit and got few examples, but didnt get it completely.
so looking for your help.

Re: replace occurance of "<br />" with ""

Posted: Wed Sep 10, 2008 7:34 am
by marcth
Sounds to me like you should want to remove all <br /> tags and wrap each paragraph in a <p></p>. Anyway, this should do the trick:

Code: Select all

 
<?php
$final = "booo<br />
<br />asdfasdfasdf";
 
$final = preg_replace("/<br \/>\s*<br \/>/", '<br />' , $final);
print $final;
?>
 

Re: replace occurance of "<br />" with ""

Posted: Wed Sep 10, 2008 8:16 am
by hemanshurpatel
Thanks buddy
it doesn solve the problem

i know i m being bit more greedy
can you explain me that expression a bit, i would be very thank full.

Regards

Hemanshu

Re: replace occurance of "<br />" with ""

Posted: Wed Sep 10, 2008 8:34 am
by marcth
Here read this. That should get you started.
preg_replace
Regular Expression Reference Sheet