Hi,
Please i'm writing a program using a regular expression .
Now , i created a string called 'this is a test' and i want to replace 'test' with 'assignment', i try this code but not working , can someone help me
Here is the code
Code:
[<?php]
$string='this is a test';
$preg_replace= preg_replace('/[a-zA-Z]/','assignment', $string);
echo $preg_replace;
[ ?>]
For simple ones like your example, str_replace is a LOT faster (processing wise).
Regular expressions should only be used to match patterns - something you don't know specifically the value of, or a pattern you need to replace (like parsing BB code).
In other words, learn how to use it with its proper designed application.
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.