search

Home  >  Q&A  >  body text

Bro, please help me

$keywords = "Keyword 1, Keyword 3, Keyword 2"

$body = "This is a piece of content, there will be html code in the content"

Now it is random Extract a value from $keywords and randomly insert it into $body. I tried it myself and it inserted it into the html tag. How can I avoid inserting it into the html tag?

$len=mb_strlen($body) ;

$rad1=rand(0,$len);

$rad2=rand(0,sizeof($keywords)-1);

$s1=mb_substr ($body,0,$rad1);

$s2=mb_substr($body,$rad1,$len);

$body = $s1.$ keywords[$rad2].$s2;

Now the code is like this, please help

1569 days ago1118

reply all(1)I'll reply

  • 大瓶可乐@php.cn

    大瓶可乐@php.cn2020-09-28 10:26:08

    You can replace the html with a placeholder first.

    After the random insertion is completed, replace the placeholder back to the old html

    reply
    0
  • Cancelreply