How can I change title to include %20 instead of spaces

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 7, 2011   (RSS)

By (Deleted User) - February 6, 2011

Hello,

I would like to add the title to a social media icon. I am using HTML5 and would like any spaces within the title to be replaced by %20 to conform to HTML5 rules.

Here's the code:

<a href="http://digg.com/submit?url=http://www.mydomain.com/motorcycle-rental/<?php echo $rental_locationsRecord['location_url'] ?>-<?php echo $rental_locationsRecord['num'] ?>&amp;title=<?php echo $rental_locationsRecord['title'] ?>" title="Click to share this on Digg"><img src="http://cdn.mydomain.com/assets/transparent.gif" class="newsprite dig" width="48" height="48" alt="Digg" /></a>

As you can see I also use a sprite to display the icon.

All I want is the <?php echo $rental_locationsRecord['title'] ?> to instead of displaying:

This is an Example Page Title

to display:

This%20is%20an%20Example%20Page%20Title

Any ideas? I have seen code like
$string = preg_replace("/\s/", '%20', $string);

But don't know how to add it!

Thanks Jono

Re: [jonoc73] How can I change title to include %20 instead of spaces

By Damon - February 7, 2011

Try this:

<?php echo rawurlencode($rental_locationsRecord['title']) ?>

That should do it.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/