managedinternet
01-29-2007, 12:05 PM
Hi guys ok my problem is this..
i have a page that scrapes content from another site
it searches the remote site using pregmatch to find the code from where it should start copying from
however when i get the code back its like
<b class=titler>Wine Tastings for Singles</b><b class=titler>Wine Tastings for Singles</b>
now...
using str_replace i have the following code
$newtitler = str_replace('<b class=titler>','', $aTitle);
$newtitler .= str_replace('</b>','', $aTitle);
$newtitle = $newtitler;
$aTitle is the variable that the script defines for the scraped title
would seem easy enough .. you'd assume that $newtitle would now be
Wine Tastings for Singles
I then use str_replace again to replace the spaces with a -
however,
when i use fopen i get this
Warning: fclose(): supplied argument is not a valid stream resource in /home/pettrain/public_html/articles/getContent.php on line 184
<b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b><b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b>
Warning: fopen(<b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b><b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b><b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b><b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b>.php) [function.fopen]: failed to open stream: No such file or directory
So.. it hasnt removed the bit of code using str_replace
i wanted it removed.. instead i get the above
anyone help please .. its very urgent
Thanks in advance
I have tried different ways etc but nothing will work
If you could sort it so that it doesnt include the <b class > bit of html in the following code snippet that would solve all my problems
Here is the code bits
Content scraping bit ( there is a lot more but this is what grabs & stores the content )
if (preg_match("/(<b class=titler>)(.*)(<\/b>?)/", $h->body, $title))
$aTitle = htmlentities($title[0], ENT_QUOTES);
else
$aTitle = "ERROR";
My fopen bit of code ( $template is stored on another included page )
$newtitler = str_replace('<b class=titler>','', $aTitle);
$newtitler .= str_replace('</b>','', $aTitle);
$newtitle = $newtitler;
$newfilename = str_replace(' ','-', $newtitle);
$newtitler2 = str_replace('<b-class=titler>','', $newfilename);
$newtitler2 .= str_replace('</b>','', $newfilename);
$newtitle2 = $newtitler2;
$newfilename2 = str_replace(' ','-', $newtitle2);
$ext = '.php';
echo $newfilename;
$filename = $newfilename2; //the name of our file.
$filename .= $ext;
$filecontent = $template; //what we will be writing to our file.
$strlength = strlen($filecontent); //gets the length of our $content string.
$create = fopen($filename, "w"); //uses fopen to create our file.
$write = fwrite($create, $filecontent, $strlength); //writes our string to our file.
$close = fclose($create); //closes our file
}
}
i have a page that scrapes content from another site
it searches the remote site using pregmatch to find the code from where it should start copying from
however when i get the code back its like
<b class=titler>Wine Tastings for Singles</b><b class=titler>Wine Tastings for Singles</b>
now...
using str_replace i have the following code
$newtitler = str_replace('<b class=titler>','', $aTitle);
$newtitler .= str_replace('</b>','', $aTitle);
$newtitle = $newtitler;
$aTitle is the variable that the script defines for the scraped title
would seem easy enough .. you'd assume that $newtitle would now be
Wine Tastings for Singles
I then use str_replace again to replace the spaces with a -
however,
when i use fopen i get this
Warning: fclose(): supplied argument is not a valid stream resource in /home/pettrain/public_html/articles/getContent.php on line 184
<b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b><b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b>
Warning: fopen(<b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b><b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b><b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b><b-class=titler>Getting-to-the-Root-of-Nutrition:-The-Pillars-of-Nutrition</b>.php) [function.fopen]: failed to open stream: No such file or directory
So.. it hasnt removed the bit of code using str_replace
i wanted it removed.. instead i get the above
anyone help please .. its very urgent
Thanks in advance
I have tried different ways etc but nothing will work
If you could sort it so that it doesnt include the <b class > bit of html in the following code snippet that would solve all my problems
Here is the code bits
Content scraping bit ( there is a lot more but this is what grabs & stores the content )
if (preg_match("/(<b class=titler>)(.*)(<\/b>?)/", $h->body, $title))
$aTitle = htmlentities($title[0], ENT_QUOTES);
else
$aTitle = "ERROR";
My fopen bit of code ( $template is stored on another included page )
$newtitler = str_replace('<b class=titler>','', $aTitle);
$newtitler .= str_replace('</b>','', $aTitle);
$newtitle = $newtitler;
$newfilename = str_replace(' ','-', $newtitle);
$newtitler2 = str_replace('<b-class=titler>','', $newfilename);
$newtitler2 .= str_replace('</b>','', $newfilename);
$newtitle2 = $newtitler2;
$newfilename2 = str_replace(' ','-', $newtitle2);
$ext = '.php';
echo $newfilename;
$filename = $newfilename2; //the name of our file.
$filename .= $ext;
$filecontent = $template; //what we will be writing to our file.
$strlength = strlen($filecontent); //gets the length of our $content string.
$create = fopen($filename, "w"); //uses fopen to create our file.
$write = fwrite($create, $filecontent, $strlength); //writes our string to our file.
$close = fclose($create); //closes our file
}
}