简体   繁体   English

使用php解析html

[英]parse the html using php

i want to get only the parse value of the html field here's my html. 我只想获取html字段的解析值,这是我的html。

 <tr valign="baseline">
   <td nowrap align="left"><label>data:</label></td>
     <td><input type="text" name="data" id="data" size="32" value=""></td>
   </tr>

and here's my jquery inside onclick function. 这是我在onclick函数中的jQuery。

data =$("#try").html();

  $("#data").val(data);

            console.log("error");

and here's the result that display in the field 这是显示在字段中的结果

<p class="1">1</p><p class="2">2</p><p class="3">3</p>

i want to get only the value of P. its like 123 using php hope anyone can help me as soon as possible. 我只想获取P的值。使用php像123一样,希望有人能尽快帮助我。 thanks in advance. 提前致谢。

Use .text() instead of html() 使用.text()而不是html()

 var data = $("#try p").text(); $("#data").val(data); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr valign="baseline"> <td nowrap align="left"> <label>data:</label> </td> <td> <input type="text" name="data" id="data" size="32" value=""> </td> </tr> </table> <div id="try"> <p class="1">1</p> <p class="2">2</p> <p class="3">3</p> </div> 

your description is a little confusing. 您的描述有点混乱。 But if I got it right you end up with a string like 但是如果我做对了,你最终会得到一个像

<p class="1">1</p><p class="2">2</p><p class="3">3</p>

And you have to filter that string in PHP, not in JS. 而且您必须在PHP中而不是JS中过滤该字符串。

If so, just use strip_tags 如果是这样,只需使用strip_tags

echo strip_tags('<p class="1">1</p><p class="2">2</p><p class="3">3</p>');

Hope that is what you are looking for 希望那是你想要的

Regards, 问候,

Stefan 斯特凡

As I understand you want to get the value of the text input without p tags you can do it using jquery by following jquery script 据我了解,您想获取不带p标签的文本输入的值,可以通过遵循jquery脚本使用jquery来实现

data = $("#data").val();

alert($(data).text());
</pre>

or by PHP using $data = $_GET ['data']; echo strip_tags($data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM