preg_replace hell
Posted
by Jason
on Stack Overflow
See other posts from Stack Overflow
or by Jason
Published on 2010-03-11T19:45:52Z
Indexed on
2010/03/11
19:49 UTC
Read the original article
Hit count: 254
php
|preg-replace
I'm trying to use preg_replace to get some data from a remote page, but I'm having a bit of an issue when it comes to sorting out the pattern.
function getData($Url){
$str = file_get_contents($Url);
if(strlen($str)>0){
preg_match("/\<span class=\"SectionHeader\"\>title\</span>/<br/>/\<div class=\"header2\"\>(.*)\</div\></span\>/",$str,$title);
return $title[1];
} }
Here's the HTML as is before I ended up throwing a million slashes at it (looks like I forgot a part or two):
<span class="cell CellFullWidth"><span class="SectionHeader">mytitle</span><br/><div class="Center">Event Name</div></span>
Where Event Name is the data I want to return in my function.
Thanks a lot guys, this is a pain in the ass.
© Stack Overflow or respective owner