0

Here's what I want:

$practice_name = preg_replace("/\([^\)]+\)/","",$practice_name);
echo($practice_name);

But that does not work when I reference the variable then.

This however does work.

echo(preg_replace("/\([^\)]+\)/","",$practice_name));

But I do not want to update my code every time I reference $practice_name, I only want to update where the variable gets assigned.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Casperjames
1

I cannot reproduce your error.

$practice_name = 'a really long ()  name what () is (this) replacing';
echo "<br /> xx ".$practice_name . "<br />";
 echo "pr " . preg_replace("/\([^\)]+\)/","",$practice_name) . "<br />";
    $practice_name = preg_replace("/\([^\)]+\)/","",$practice_name);
    echo "zz " .$practice_name . "<br />";
	echo ($practice_name);

output as expected:
xx a really long () name what () is (this) replacing
pr a really long () name what () is replacing
zz a really long () name what () is replacing
a really long () name what () is replacing
(this) was removed from the original string in both cases.

0

I should have posted more code in the beginning, I finally found that it was excluding the whole thing because it was inside of a false if statement. Thank you for your help though.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.