Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing unwanted symbols in string 1

Status
Not open for further replies.

overyde

Programmer
May 27, 2003
226
ZA
Hi,

If I want to delete unwanted characters from my variable (say info from a form), is this the best way to do this:
Code:
$restricted = array("!", "@", "#", "$", "%", "^", "&", "*", "/", "(", ")", "|", "\\");

$output = str_replace($restricted, "", "$input");
$input = "oranges &*/()|\* and lemons";
print "$output";

Reality is built on a foundation of dreams.
 
This is certainly a good way to do it.
An alternative is always a regular expression. Here then comes the 'timing' issue which is that regular expressions usually have a timing advantage only if the same expression is used multiple times. However, this is quite theoretical as the amount of data parsed probably is small scale.
If you have a good server that is not taxed to its limits then either way should be fine.
 
DRJ478,
Don't know what I would do without you and sleipnir214.Your knowledge on the subject is profound, you guys have helped me out alot in the past.
Thank-you!

Reality is built on a foundation of dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top