Jump to content

Remove carriage returns from scraped HTML


webhead2

Recommended Posts

Hello and thanks in advance.  This is becoming quite the pesky problem!

 

I am developing a script that scrapes some html from partner websites (I have no control over the formatting).  The content gets inserted to a Wordpress database :)

 

The problem I am having is when a carriage return is placed in the middle of a tag. Like so:

 

<body
style="color: rgb(0, 0, 0); background-color: rgb(79, 105, 59);"
alink="#000099" link="#000099" vlink="#990099">

 

When displayed in wordpress,  it actuall prints out

"style="color: rgb(0, 0, 0); background-color: rgb(79, 105, 59);"
alink="#000099" link="#000099" vlink="#990099">"

 

because of the carriage return. 

 

I've tried this code to remove them:

$body = str_replace(chr(13),' ',$body);
$body = str_replace("\r"," ",$body);
$body = str_replace("\n"," ",$body);

 

The above does not seem to work. 

 

Thanks for looking at my problem!

:chomp:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.