alexchenco alexchenco - 1 year ago 75
PHP Question

Turning a name into a URL-friendly string in PHP?

Possible Duplicate:

URL Friendly Username in PHP?

I have something like this:

'mrt1' => 'Zhongxiao Dunhua Sun'

which will be included into an anchor link like this:

<a href="'. $mrt1 .'">'. $mrt1 .'</a>

I want the output to be something like this:

<a href="zhongxiao-dunhua-sun">Zhongxiao Dunhua Sun</a>

How to do it so that I can turn that name into a URL-frienly string (so I can place it in the href attribute)?

Answer Source
$s = 'Zhongxiao Dunhua Sun';
preg_replace('/\W+/', '-', strtolower($s));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download