Search code examples
phpstringsubstr

Cut string from one point to another point in PHP


I want to make script that his action is to cut string from one point to another point.

for example:

<div id="box" style="font-size:bold;height:30px;width:100px;border: 1px solid black">xx</div>

i want that the script will cut all the style., and it will be something like:

<div id="box">xx </div>

how can I do it ?


Solution

  • If all you want to do is replace the style attribute you can do this:

    $str = '<div id="box" style="font-size:bold;height:30px;width:100px;border: 1px solid black">xx</div>';
    $str = preg_replace('/ style=\"[^\"]*\"/', '', $str);