LoginSignup
0
0

More than 3 years have passed since last update.

PHPで文字列の中でハッシュタグから始まるワードを配列にして取り出す方法

Last updated at Posted at 2021-02-08
<?php

$tagsText = '#ラーメン #カレー #  aaaaaaaa bbbbbbbb #カツ丼 #シチュー #肉じゃが cccccccc';
$result = preg_match_all('/#([^\s#]+)/', str_replace(' ', ' ', $tagsText), $m) ? $m[1] : [];
print_r($result);
// 結果 [ラーメン, カレー, カツ丼, シチュー, 肉じゃが]
0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0