@Sometihngのようなユーザーを探すためにPHPで関数を作成しようとしていますが、それらのプロファイルへのリンクを文字列に入れますが、使用するときはを返します。 userTags()を再宣言できません。あなたはどこに問題があるのか、何が間違っているのか知っていますか?ここに私のコードです。助けてくれてありがとう。PHPの再帰関数は致命的なエラーを返します
$comment = "Hey @Name how are you?? And how is @AnotherName. Also have you seen @SomeName ??";
function userTags($startFrom) {
$pos = strpos($comment, '@', $startFrom);
if ($pos !== false) {
$pos1 = strpos($comment, ' ', $pos);
if ($pos1 !== false) {
$insert_string = '<a href="profile.php?owner=somewhere">';
$insert_string1 = "</a>";
$comment = substr_replace($comment, $insert_string1, $pos1, 0);
$comment = substr_replace($comment, $insert_string, $pos, 0);
userTags($pos1);
}
}
}
userTags関数を再宣言しようとしているようです。たぶん同じファイルを2回含むのでしょうか? require/includeの代わりにrequire_onceまたはinclude_onceを試してください – rjdown
エラーメッセージには、関数 'userTags()'を2回定義しましたが、これは許可されていません。たぶん同じスクリプトに複数回含まれているファイルで一度だけ定義したのでしょうか? (おそらく間接的な包含を介してですか?) – axiac
問題はあなたが投稿したコードにありません。 –