Jump to content

[SOLVED] Read tag in file


ari_aaron

Recommended Posts

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

<?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.

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.