简体   繁体   中英

PHP Insert HTML markup in the middle of other markup without breaking it

I am trying to embed a contact form (..) globally inside my wordpress posts without breaking the post's markup.

Say I have this code:

$str = 'My post text here my post text here<ul>
<li>Text</li>
<li>Text2</li>
</ul> more text';

I have a PHP code which inserts text in the middle of $str (or post_content in our case), but how can I make sure I am not breaking the code although its considered in the middle? I hope my questions is clear.

I'll give more details: I am trying to add a php code which inserts some html markup into wordpress posts in my blog. the thing is, that in some posts its just fine but in other posts it breaks the html code (incase the output comes out in the middle of an <li> element or <table> ) so I am trying to find a way to embed my text in the middle of the post without breaking the current HTML.

You can do something like:

$myText =  "testing  something";
$str = '<ul>
<li>Text</li>
<li>'. $myText.'</li>
</ul>';  

Here is a DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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