Jump to content

Archived

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

3s2ng

simple regex

Recommended Posts

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

Share this post


Link to post
Share on other sites
[code]
<pre>
<?php
$names = array(
'Mark',
'Mark & Lester',
'Yoy & Me'
);

foreach ($names as &$name) {
$name = preg_replace('/\s+&\s+/', '_', $name);
}

print_r($names);

?>
</pre>
[/code]

Share this post


Link to post
Share on other sites

×

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.