0

Hi i'd like to store an echo's results in a variable and i want the results not the string itself... What i'm doing is:

ob_start();
echo "<script>document.write(window.innerWidth);</script>";
$content = ob_get_clean();
echo 'Before:'.$content.'<br/>'; //I need results of this echo which is : "<script>document.write(window.innerWidth);</script>1366" in my case( i need that 1366 thing :) 
//What i tried:
$content = str_replace('<script>document.write(window.innerWidth);</script>','',$content);
echo 'After:'.$content.'<br/>'; //Result is nothing :) without those things nothings left :)
//I want to store that 1366 in a $width :) 
behzad.robot
  • 587
  • 1
  • 5
  • 16
  • I'm confused because echo is not a unction and doesn't return a result, so where this result is coming from I am unsure, could you please clarify whats going in and what you want coming out of all this, thanks. – Dendromaniac Apr 27 '15 at 19:41
  • Output Buffering get the echoed content BEFORE it's rendered, and before javascript is executed by the browser. You really need to review basics. If you want to pass the window width to PHP you better send it via $_POST, but I can't see the reason why you would want to do that. – Francesco Zaffaroni Apr 27 '15 at 20:44
  • i do know when and where we run php and where and when and where we have js running and i guess sending it via a $_POST from another page then coming to current page is my only choice any ways thanks for answering ... my original goal was to do sth like pinterest showing posts in different columns who really dont care about each other's height ...well let's forget about my original goal i handled it somehow using Jquery and Ajax thanks again for answering... ;) – behzad.robot Apr 30 '15 at 20:37

0 Answers0