Jump to content

[SOLVED] Get Value Of Value


papaface

Recommended Posts

the problem is you would need a time machine to do that on the same page because php processes prehypertext thus that element doesn't exist when php exist and dies when php comes back alive.

 

PHP can interact with the end user using the common HTTP protocols of GET/POST  to pass variables, but again that can only happen on the second page load.

 

 

there is also the $_SERVER superglobal array (http://us2.php.net/manual/en/reserved.variables.server.php) that contains some useful info

Link to comment
Share on other sites

No. I dont mean like that. I mean how can I get the value of that specific element as a string.

like

<?php
function getAttribute($attrib, $tag){
  //get attribute from html tag
  $re = '/'.$attrib.'=["\']?([^"\' ]*)["\' ]/is';
  preg_match($re, $tag, $match);
  if($match){
    return urldecode($match[1]);
  }else {
    return false;
  }
}
$tag = '<param name="src" value="http://someurl.com/hello.php">';
echo    getAttribute("value", $tag);
?>

That will get the value of any element in the string, but I want it get the value when the element's name is "src".

Link to comment
Share on other sites

actually read the file's content not pass data via a protocol I see.

 

you can do this very simply actually

<?php
function getAttribute($attrib, $tag){
  //get attribute from html tag
  $re = '/'.$attrib.'=["\']?([^"\' ]*)["\' ]/is';
  preg_match($re, $tag, $match);
  if($match){
    return urldecode($match[1]);
  }else {
    return false;
  }
}
$tag = '<param name="src" value="http://someurl.com/hello.php">';
if(stristr($tag, "name=\"src\""){
   echo    getAttribute("value", $tag);
}
else{
   echo "name does not equal src";
}
?>

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.