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

Link to comment
Share on other sites

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