Jump to content

[SOLVED] using preg_replace


Vidya_tr

Recommended Posts

what do the tags such as \s , \w , \d etc indicate in preg_replace??

 

I am not able to get this...

 

<?php

$string = 'April 15, 2003';

$pattern = '/(\w+) (\d+), (\d+)/i';

$replacement = '${1}1,$3';

echo preg_replace($pattern, $replacement, $string);

?>

 

Also please tell me how does the delimiter parenthesis work in preg_replace...

 

 

Link to comment
https://forums.phpfreaks.com/topic/152024-solved-using-preg_replace/
Share on other sites

Straight from DarkWater's regex tutorial:

 

/\d/ #matches any digit

/\D/ #matches any NON-DIGIT

/\w/ #matches any word character (which includes the underscore and digits, so it's like [a-zA-Z0-9_])

/\W/ #matches any NON-WORD character

/\s/ #matches any whitespace character like a literal space, a tab, and a newline

/\S/ #matches any NON-WHITESPACE character

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.