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

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

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";
}
?>

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.