Cool Cool - 5 months ago 14
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
preg_replace()
to replace the
***Image URL
with an empty string, look like string here:

-Website URL


I always have problem with
preg_replace()
.

Please help me! Thank you!!!!

Answer

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

$res = preg_replace('/^-?(.+)\*{3}.+$/', '\1', '-Website URL***Image URL');
echo $res;
Comments