ari_aaron Posted February 1, 2007 Share Posted February 1, 2007 I think I need to use Regular Expressions here, but I'm not sure how: I need to read a file, and get what's in the span with the ID of "name". For example, if it had <span id="name">WHAT'S HERE??</span> i would want "WHAT'S HERE??" Thanks, ari_aaron Link to comment https://forums.phpfreaks.com/topic/36680-solved-read-tag-in-file/ Share on other sites More sharing options...
pocobueno1388 Posted February 1, 2007 Share Posted February 1, 2007 <?php $var = "<span id='name'>WHAT'S HERE??</span>"; $new_var = substr("$var", 16, 13); echo $new_var; ?> This would only work for that specific span id of course...I'm not sure of how you could detect the start and end of the tag...but if your looking for a span with an 'id' conating 4 letters such as name, that should work. <b>Edit:</b> I was wrong...you might have to edit the "13" depending on how long the tag is in between. I will see if I can come up with a better way to answer your question. Link to comment https://forums.phpfreaks.com/topic/36680-solved-read-tag-in-file/#findComment-174918 Share on other sites More sharing options...
pocobueno1388 Posted February 1, 2007 Share Posted February 1, 2007 This seems to work perfect ^^ <?php $var = "<span id='name'>test test test test</span>"; $new_var = explode('>' , $var); echo $new_var[1]; ?> $new_var[1] holds what is inside of the tag. Link to comment https://forums.phpfreaks.com/topic/36680-solved-read-tag-in-file/#findComment-174929 Share on other sites More sharing options...
ari_aaron Posted February 2, 2007 Author Share Posted February 2, 2007 I need to read a file, and get what's in the span with the ID of "name". I'm using $contents = file_get_contents($url); and I need to find the thing in the tag, which is somewhere in the page. Link to comment https://forums.phpfreaks.com/topic/36680-solved-read-tag-in-file/#findComment-175094 Share on other sites More sharing options...
fert Posted February 2, 2007 Share Posted February 2, 2007 preg_match_all("/<span id='name'>(.*?)<\/span>/",$contents,$matches); print_r($matches) Link to comment https://forums.phpfreaks.com/topic/36680-solved-read-tag-in-file/#findComment-175111 Share on other sites More sharing options...
ari_aaron Posted February 2, 2007 Author Share Posted February 2, 2007 Output: Array ( [0] => Array ( [0] => WHAT'S HERE?? ) [1] => Array ( [0] => WHAT'S HERE?? ) ) How do I get access to it without all that array stuff. I tried $matches[0], and it outputted "Array". EDIT: got it. it was $matches[0][0] Link to comment https://forums.phpfreaks.com/topic/36680-solved-read-tag-in-file/#findComment-175135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.