/    Sign up×
Community /Pin to ProfileBookmark

Finding line breaks in HTML?

Hi I’m using str_replace() to remove some text and html code from a string. How do I match a line break in the html code? It literally looks like this in the html:

Schedules are subject to change without notice. For most up to date information, please log into our Online Booking System to search for flights required and availability.<br />
<br />

I can’t match the second <br />, presumably because I need to include a line break in my “needle”. I’ve tried a bunch of things and can’t get a result. Thanks in advance.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@hamburglarFeb 14.2012 — That's very surprising.

Have you tried using preg_replace() function?
Copy linkTweet thisAlerts:
@robahasauthorFeb 14.2012 — Here's with preg_replace(). I also tried n btw. As is here, it works. But if I add a second <br /> (which is on a separate line in the html), no luck. My $remotecontent variable contains a section of html read from another website.

[code=php]$remotecontent = preg_replace( "/r/", "", $remotecontent);
$remotecontent = str_replace("For most up to date information, please log into our Online Booking System to search for flights required and availability.<br />", "" , $remotecontent);
echo $remotecontent;[/code]
Copy linkTweet thisAlerts:
@robahasauthorFeb 14.2012 — I figured out one problem and went on to another one... So the <br /> tags got reduced to <br/> when loaded to the variable. Now I can find them. My next odd thing is I search for a string ending in <br/><br/><br/><br/> and everything but the ending breack tags is replaced (I need to get rid of the space these create). Here is the code:

[code=php]$remotecontent = preg_replace( "/n/", "", $remotecontent);
$remotecontent = str_replace("For most up to date information, please log into our Online Booking System to search for flights required and availability.<br/><br/><br/><br/>", "" , $remotecontent);
echo $remotecontent;[/code]


It runs fine and the relevant text is deleted, but the four breaks still show up in the output! I don't get it.

Thanks
×

Success!

Help @robahas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...