![]() |
|
|
Welcome to the { mindfrost82.com } forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Re: PHP: automatically replace alphanumeric charactersin a string
Here is the PHP code that does what you requested.
<?php $string = "?M&y S8tr~i^ng&;"; $new_string = preg_replace("/[^a-zA-Z]/", "_", $string); echo $new_string ?> Hope This Helps Stan Forrest Senior Web Developer Applied Technology Group, Inc. |
|
|||
|
Re: PHP: automatically replace alphanumeric characters in a string
..oO(AngryCloud)
>Yes, this does help, although it is only alphabetic. > >Will changing the line to this make it alphanumeric?: > >$new_string = preg_replace("/[^a-zA-Z0-9]/", "_", $string); Did you try it? ;-) You could also use this shorter pattern: /[^a-z\d]/i Should be the same (\d matches decimals and the /i modifier makes the entire thing case-insensitive). Micha |
|
|||
|
Re: PHP: automatically replace alphanumeric charactersin a string
Yes, if you change the line
$new_string = preg_replace("/[^a-zA-Z]/", "_", $string); to $new_string = preg_replace("/[^a-zA-Z0-9]/", "_", $string); It will also replace any numeric character as well. Stan Forrest Senior Web Developer Applied Technology Group, Inc. |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|