Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
any help please?

i don't have much experience in PHP hope some one help me

i want to change content that's between html tags while page loading with PHP

for example..

while page loading if td tags contains "Hello" like this
XML
<td>Hello</td>


then some how i want to change it or add some word with that word to make it like this
XML
<td>Hello Too</td>


i only know it will be done with "if, then, else" with PHP

Thank You.
Posted
Comments
Sergey Alexandrovich Kryukov 2-May-14 17:22pm    
The question is unclear; and I suspect you don't know how Web works and what PHP does in general. It does not load anything. PHP code generates HTTP response in first place. Its input is the PHP code file itself and output is HTTP response. To "change" something, you need to have something different and than change is. There is no such thing.
—SA
Member 10749093 2-May-14 18:56pm    
i appreciate you response. as i said on my question i don't know much but maybe i learn something from CodeProject members. you don't have to say such things to show me yourself like what you said. thanks.
Sergey Alexandrovich Kryukov 2-May-14 19:22pm    
All right. I hope I understood your concern; please see Solution 1. If this is not what you are missing, feel free to ask further questions, but please try to be more clear.
—SA
Member 10749093 2-May-14 19:50pm    
thanks for your replay. if i'm correct, PHP will generate what i want on page and it doesn't change tags or what ever while page loading like javascript does. am i right?
Sergey Alexandrovich Kryukov 2-May-14 20:24pm    
The word "change" is simply inapplicable. In input, it's only the PHP page (or HTML with PHP), maybe some other data calculated during execution, on exit — the HTTP response, in this case, in HTML (could be anything else: images, plain text, etc).

I hope it should be clear now. Will you accept the answer formally (green "Accept" button)?

—SA

Please see my comment to the question. Probably you don't understand how PHP works and what it does. There is nothing to change. You just generate what you want. For example.

HTML
<html>
<body>

<!-- ... -->

<?php
/* ... */
if ($someCondition)
   echo '<td>Hello</td>';
else
   echo '<td>Hello 2</td>';
?>

<!-- ... -->

<body>
<html>


Please see:
http://en.wikipedia.org/wiki/Php[^],
http://en.wikipedia.org/wiki/HTTP[^],
http://www.php.net/docs.php[^],
http://www.php.net/manual/en[^].

—SA
 
Share this answer
 
v3
Member 10749093 wrote:
for example we make application on visual basic and add 1 text box and 1 button
then put command says if text box 1 . text equals "Hello" then message box . show "Hello World"

(this is just some example. hope it help you to understand)
Now I can see what do your mean. It shows where your confusion is: you think that this is done by PHP. No. You need to finally understand what happens on the server and client parts. PHP, as any other server-side scripting technology, works the way I described. After you got some page on client side, its work is already done. Do make further change, for example, to change the <td> content, you need to trigger it by something. But all your page is already on the client side, so forget PHP. All you can do it to use Javascript.

In principle, you can still use PHP, but it will be the separate HTTP request with different HTTP response. You could use Ajax for this purpose, which still is initiated in Javascript. To get the idea, please see:
http://en.wikipedia.org/wiki/Ajax_%28programming%29[^],
https://api.jquery.com/jQuery.ajax[^] (for example).

But I don't want to continue with this advanced topic. To do such things, you will need to learn processing HTTP requests with PHP (http://www.php.net/manual/en/reserved.variables.post.php[^], http://www.php.net/manual/en/reserved.variables.server.php[^]) and find the ways to figure out initial HTTP requests through URI and post data. You really need to use just Javascript to modify some of your HTML elements on some events.

This is how you can change some element's content: http://www.w3schools.com/jsref/prop_html_innerhtml.asp[^].

It's more convenient to do with jQuery:
https://api.jquery.com/html[^],
see also: https://api.jquery.com/category/selectors[^].

If (by some reason) you do some Web development and don't know Javascript, you cannot do much. jQuery is just one of highly recommended libraries of Javascript.

—SA
 
Share this answer
 
Use JavaScript, see example:
XML
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled Document</title>
<script>
function check(){
    alert('Change in progress');
    var td = document.getElementsByTagName("td");
    if (td[0].innerHTML == "hello") {
        td[0].innerHTML = "Hello World";
    }
}
</script>
</head>
<body onload="check()">
<table>
<tr>
<td>hello</td>
</tr>
</table>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900