简体   繁体   中英

How I can Store value of echo into php variable

I wanted to store value of a echo into php variable but only i get is the HTML tag not actual value that hold that tag.

Javascript

function openModal()
{
    var checked=false;
    var elements = document.getElementsByName("offer[]");
    for(var i=0; i < elements.length; i++)
    {
       if(elements[i].checked) 
       {
           ele=elements[i].value;
           alert(ele);
           checked = true;      
       }                        
    }
    document.getElementById('test').innerHTML=ele;      
}

PHP

ob_start();
echo "<label id='testH1'></label>";
$myStr = ob_get_contents();
ob_end_clean();

when i access the $myStr using 'echo "My String ".$myStr;' it will display the actual value that id hold,but when i pass this $myStr to URL,It will again display echo "<label id='testH1'></label>"

I need to pass the value of $myStr to next page via url. How i can do?

You can do a redirection with get param, or send it via form and a $_POST.

With get param you can do :

$url = 'my_page.php?param=' . urlencode($myStr);
header('Location : ' . $url);
exit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM