替换你的页面上的文字php像element.innerhtml
hello i have been searching for some php code that is something like element.innerHTML in javascript but i can't find it. i need it for some code that for example goes from 1-60 in 60 seconds but if i do that with echo it just places everything under each other and that should not happen. i need something that just replaces the text. i also don't want to reload my page every second and i don't have the ability to write to files ( i can read them). and please don't tell me that i should do it in javascript. so can someone tell me how to do this?
你好我一直在寻找一些像javascript中的element.innerHTML这样的PHP代码,但我找不到 它。 我需要它来代替一些代码,例如在60秒内从1-60开始 但是如果我用回声来做它只是将所有东西放在彼此之下而且不应该发生。 我需要一些东西才能取代文字。 我也不想每秒重新加载我的页面,我没有能力写入文件(我可以阅读它们)。 请不要告诉我,我应该在javascript中执行此操作。 也可以有人告诉我该怎么做? p> div>
You can use PHP to spit out javascript that does the replacing. There won't be a pure PHP solution to this since PHP is server-side and doesn't have access to the rendering of the page on the client side.
Suppose the text you need to change is in a <div>
tag named 'replaceMe'. You will want to use the ob_flush() functions in PHP to force out the javascript at the time you need it to display. The PHP to initialize that is
if (ob_get_level() == 0) ob_start();
Then, each time you need to update, you have something like this in your PHP code that adds to the body of the page:
echo '<script type="text/javascript" language="javascript">';
echo "document.getElementById('replaceMe').innerHTML = 'Text for this iteration';";
echo '</script>';
flush(); ob_flush();
Of course if you want to make it easier for yourself, you can make a PHP function to print all this out given an argument containing the text to replace.
Then at the end you need to have
ob_end_flush();
to replace some text try str_replace http://de3.php.net/manual/de/function.str-replace.php or case insensitive str_ireplace