How can I bold two words around a string within a string, but not overlap sentences?

前端 未结 2 1401
不思量自难忘°
不思量自难忘° 2021-01-25 13:21

I need to bold a search term and its context (within a sentence).

Consider the string:

Lorem ipsum dolor sit amet. Consectetuer adipiscing elit.

2条回答
  •  渐次进展
    2021-01-25 14:10

    Hope this helps

    $str ="your whole string ";
    if(isset($_POST['searchStr']))
    {
    $searchStr= $_POST['searchStr'];
    $str= str_replace($searchStr,''. $searchStr.'',$str);
    }
    echo "$str";
    

    if you want a case -insensitive replacement use below function

        str_ireplace() - Case-insensitive version of str_replace.
    

提交回复
热议问题