PHP更改HTML标记之间的内容 [英] PHP Change Content between HTML tags

查看:77
本文介绍了PHP更改HTML标记之间的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么帮助吗?



i没有太多的PHP经验希望有人帮助我



i想要在页面加载PHP时改变html标签之间的内容



例如..



页面加载,如果td标签包含Hello,就像这样

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

<td>Hello</td>





然后一些我想如何改变它或添加一些单词来使它像这样



then some how i want to change it or add some word with that word to make it like this

<td>Hello Too</td>





i只知道它将用if,then,else用PHP完成



谢谢。



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

Thank You.

推荐答案

请参阅我对该问题的评论。可能你不明白PHP是如何工作的以及它的作用。没有什么可以改变的。你只需要生成你想要的东西。例如。



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>
<body>

<!-- ... -->

<?php
/* ... */
if (


someCondition)
echo ' < td> Hello< / TD>';
else
echo ' < td> Hello 2< / td>';
?>

<! - ... - >

< body >
< html >
someCondition) echo '<td>Hello</td>'; else echo '<td>Hello 2</td>'; ?> <!-- ... --> <body> <html>





请参阅:

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



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


会员10749093写道:
Member 10749093 wrote:

例如我们在visual basic上创建应用程序并添加1个文本框和1个按钮

然后把命令说成文本框1。文本等于Hello然后消息框。显示Hello World



(这只是一些例子。希望它能帮助你理解)

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)

现在我可以看到你的意思了。它显示了你的困惑:你认为这是由PHP完成的。不需要。您需要最终了解服务器和客户端部件上发生的情况。 PHP,与任何其他服务器端脚本技术一样,按照我描述的方式工作。在客户端获得一些页面后,它的工作已经完成。进行进一步更改,例如,更改< td> 内容,您需要通过某些内容触发它。但是你的所有页面都已经在客户端,所以忘了PHP。所有你可以使用Javascript。



原则上,您仍然可以使用PHP,但它将是具有不同HTTP响应的单独HTTP请求。你可以使用Ajax来实现这个目的,它仍然是在Javascript中启动的。要了解这个想法,请参阅:

http://en.wikipedia.org/ wiki / Ajax_%28programming%29 [ ^ ],

https://api.jquery.com/jQuery.ajax [ ^ ](例如)。



但我不想继续这个高级主题。要做这些事情,您需要学习使用PHP处理HTTP请求( http:// www。 php.net/manual/en/reserved.variables.post.php [ ^ ], http:// www。 php.net/manual/en/reserved.variables.server.php [ ^ ])并找到通过URI和发布数据来确定初始HTTP请求的方法。你真的需要只使用Javascript来修改某些事件上的一些HTML元素。



这是你可以改变元素内容的方法: http://www.w3schools.com/jsref/prop_html_innerhtml.asp [ ^ ]。



使用jQuery更方便:

https://api.jquery.com/html [ ^ ],

另见:https://api.jquery.com/category/selectors [ ^ ]。



如果(由于某种原因)你做了一些Web开发并且不了解Javascript,那么你做不了多少。 jQuery只是强烈推荐的Javascript库之一。



-SA

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


这篇关于PHP更改HTML标记之间的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆