Cool Cool - 1 year ago 73
PHP Question

PHP - Using preg_replace() Only Specific Part Of String

I have a string, for example:

-Website URL***Image URL

I want to use
to replace the
***Image URL
with an empty string, look like string here:

-Website URL

I always have problem with

Please help me! Thank you!!!!

Answer Source

Take all after the minus at string beginning and till 3 stars

$res = preg_replace('/^-?(.+)\*{3}.+$/', '\1', '-Website URL***Image URL');
echo $res;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download