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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hemanshurpatel
Forum Newbie
Posts: 6
Joined: Wed Sep 10, 2008 6:25 am

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

Post 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
hemanshurpatel
Forum Newbie
Posts: 6
Joined: Wed Sep 10, 2008 6:25 am

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

Post 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.
marcth
Forum Contributor
Posts: 142
Joined: Mon Aug 25, 2008 8:16 am

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

Post 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;
?>
 
hemanshurpatel
Forum Newbie
Posts: 6
Joined: Wed Sep 10, 2008 6:25 am

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

Post 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
marcth
Forum Contributor
Posts: 142
Joined: Mon Aug 25, 2008 8:16 am

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

Post by marcth »

Here read this. That should get you started.
preg_replace
Regular Expression Reference Sheet
Post Reply