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.

Recommended Answers

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 …

Jump to Post

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.