phpcpu-wordtruncate

Remove first two words from a string


I have a string:

$string = "R 124 This is my message";

At times, the string may change, such as:

$string = "R 1345255 This is another message";

Using PHP, what's the best way to remove the first two "words" (e.g., the initial "R" and then the subsequent numbers)?


Solution

  • try

    $result = preg_replace('/^R \\d+ /', '', $string, 1);
    

    or (if you want your spaces to be written in a more visible style)

    $result = preg_replace('/^R\\x20\\d+\\x20/', '', $string, 1);