There are links on the page.

It is necessary to remove the start and end slash trim ($ str, '/') in the link attributes, change the slashes to the hyphen (which are in the link path), and add .html ...

I don't understand how to do it, I try to do regular expressions, but it doesn't work.

<p> <a title="fdfds" href="/contact/us" target="_self">click here</a> <a href="/back/us" title="fdsd" target="_self">click here</a> </p> 

It should look like this:

  <p> <a title="fdfds" href="contact-us.html" target="_self">click here</a> <a href="back-us.html" title="fdsd" target="_self">click here</a> </p> 

    1 answer 1

    It's easier to use the HTML parser and there you have to change what you need:

     require 'simple_html_dom.php'; $str = <<<DATA <p> <a title="fdfds" href="/contact/us" target="_self">click here</a> <a href="/back/us" title="fdsd" target="_self">click here</a> </p> DATA; $html = str_get_html($str); foreach($html->find('a') as $link){ $href = $link->href; $link->href = str_replace('/', '-', trim($href, '/')) . '.html'; }