Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 基于Div元素拆分字符串_Php_Html_String - Fatal编程技术网

Php 基于Div元素拆分字符串

Php 基于Div元素拆分字符串,php,html,string,Php,Html,String,我在PHP中有一个字符串变量 <html> <body> <div style="height: 10px; line-height: 10px;"> </div> </body> </html> 我想把那根绳子分成两段 字符串1 <html> <body> <div style="height: 10px; line-height: 10px;"> 字符串2

我在PHP中有一个字符串变量

<html>
 <body>
   <div style="height: 10px; line-height: 10px;">
   </div>
 </body>
</html>
我想把那根绳子分成两段

字符串1

<html>
 <body>
   <div style="height: 10px; line-height: 10px;">
字符串2

 </div>
 </body>
</html>
然后将向该DIV中插入一些内容

注意:上面的字符串只是一个示例来解释我想要什么,我有一个1000多行的HTML标记

正如有人问你在PHP中为查询做了哪些努力

$pieces = split('<div style="height: 10px; line-height: 10px;">', $template); 

但是它包含整个标记,而不是拆分的标记

<html>
 <body>
   <div style="height: 10px; line-height: 10px;">
   xyz123
   </div>
 </body>
</html>
然后访问这两个部分,如

$result[0] and $result[1]

注意:xyz123用作演示用途的唯一字符串。

是否需要将内容插入div?试试看:

$new = str_replace('<div style="height: 10px; line-height: 10px;">', '<div style="height: 10px; line-height: 10px;">' . $yourContent, $template);

您可以尝试使用字符串插值:{$yourPHPContent}不,我不能。。。字符串实际上来自第三方网站。。。它实际上是一个电子邮件模板。。。我想拆分它,并想在该分区的一侧输入订单详细信息标记。。。我有一个电子商务网站,它总是更好地解释你想做什么,而不仅仅是如何做。因此,考虑到您想要做什么,您最好使用HTML DOM解析器,而不是与所有可能的情况作斗争。我尝试通过传递它,但它返回了正确的结果。您的意思是传递div元素以分解函数?你得到了什么结果?
$new = str_replace('<div style="height: 10px; line-height: 10px;">', '<div style="height: 10px; line-height: 10px;">' . $yourContent, $template);