Search code examples
phppreg-match

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

Solution

  • 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