Search code examples
phpstrpos

How can I get the word after a string?


I have a string which somewhere contains Style Name: Something. What I want to be able to do is search for Style Name: and get back Something or whatever that value is.

I know I need to do something with strpos to search the string but I'm pretty much stuck on getting the value.


Solution

  • With positive lookbehind,

    <?php
    $string="Style Name: Something with colorful";
    preg_match('/(?<=Style Name: )\S+/i', $string, $match);
    echo $match[0];
    ?>
    

    DEMO: https://3v4l.org/OICqF