dantey89 dantey89 - 7 months ago 40
PHP Question

Write regular expression in preg_replace

I still don't understand how regular expression work with preg_replace. I have some url in text:



I want to change it so it become this



preg_replace(" 'no_mater_what_1'.php'no_mater_what_2' " , 'no_mater_what_1'/ , $some_var);

Answer Source

But why not simply do this:

$replace = explode('.php',$some_var);
$replace = $replace[0] . '/';

Because that I find it necessary to use a regular expression, because ".php" is not repeated in the string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download