问题描述:

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?

网友答案:

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

相关阅读:
Top