Jump to content


Photo

simple regex


  • Please log in to reply
1 reply to this topic

#1 3s2ng

3s2ng
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 05 October 2006 - 02:25 PM

Hello Freaks,

I have an array which contains names,

example:

$name = array("Mark", "Mark & Lester", "Yoy & Me");

What I want is to change Mark & Lester to Mark_Lester.

I hope you can help me.

Thanks
MARK

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 05 October 2006 - 03:43 PM

<pre>
<?php
	$names = array(
		'Mark',
		'Mark & Lester',
		'Yoy & Me'
	);
	
	foreach ($names as &$name) {
		$name = preg_replace('/\s+&\s+/', '_', $name);
	}
	
	print_r($names);
	
?>
</pre>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users