preg_match all words start with an @?

前端 未结 5 1893
栀梦
栀梦 2021-01-25 08:05

i\'m not very firm with regular Expressions, so i have to ask you:

How to find out with PHP if a string contains a word starting with @ ??

e.g. i have a string l

5条回答
  •  余生分开走
    2021-01-25 09:10

    break your string up like this:

    $string = 'simple sentence with five words';
    $words = explode(' ', $string );
    

    Then you can loop trough the array and check if the first character of each word equals "@":

    if ($stringInTheArray[0] == "@")
    

提交回复
热议问题