爆発を使用して、@ の前にある単語を処理できます...それは本当に何をしたいかによって異なります。
//Store the string in a variable
$textVar = "The quick brown @fox jumps @over the @lazy dog.";
//Use explode to separate words
$words = explode(" ", $textVar);
//Check all the variables in the array, if the first character is a @
//keep it, else, unset it
foreach($words as $key=>$val) {
if(substr($val, 0, 1) != "@") {
unset($words[$key]);
} else {
$words[$key] = "<a href='#'>".$words[$key]."</a>";
}
}
//You can now printout the array and you will get only the words that start with @
foreach($words as $word) {
echo $word."<br>";
}
@ を持たない文字列を保持し、内破を使用してすべてをまとめることもできます。
//Store the string in a variable
$textVar = "The quick brown @fox jumps @over the @lazy dog.";
//Use explode to separate words
$words = explode(" ", $textVar);
//Check all the variables in the array, if the first character is a @
//keep it, else, unset it
foreach($words as $key=>$val) {
if(substr($val, 0, 1) != "@") {
//Do nothing
} else {
$words[$key] = "<a href='#'>".$words[$key]."</a>";
}
}
//You can now printout the string
$words = implode($words, " ");
echo $words;