Arvis Arvis - 3 months ago 15
PHP Question

Replace ">" and every character after the special character

i am a beginner in PHP and would want to replace ">" and every other character after it in a string.

http://www.example.com/>testmail

Answer

This should do the trick

<?php
 $string = 'http://www.example.com/>testmail';
 $pattern = '/(>(.*?))$/i';
 $replacement = 'helloWorld';
 echo preg_replace($pattern, $replacement, $string);

More about preg_replace; http://php.net/manual/en/function.preg-replace.php

Comments