Welcome Guest, Not a member yet? Register   Sign In
Converting text to Safe Tags
#1

[eluser]zeedy2k[/eluser]
Is there any fucntions that I can use that will allow me to create tags for use in URL's?

for example. Game's & Application's would be converted to something like games_applications?

Thanks
Robert
#2

[eluser]Pascal Kriete[/eluser]
There isn't a built in one that I'm aware of (the inflector helper will do spaces).

It's not hard though.
Code:
$text = "whatever&$*()#U you want-in_#*(%Y# the *$(#&# url;";

// Turn spaces into underscores
$text = str_replace(' ', '_', $text);

// Define unwanted characters
$unwanted = array('&', '$', '#'); //etc

// Kill them
$text = str_replace($unwanted, '', $text);
#3

[eluser]Pascal Kriete[/eluser]
Better yet:

Code:
// Do spaces as above

$text = preg_replace('/([^a-zA-Z0-9]+)/', '', $text);
#4

[eluser]zeedy2k[/eluser]
Excellent... thanks for the quick reply.
#5

[eluser]Seppo[/eluser]
As a matter of fact there is a function in the URL helper to do this.

url_title()

Takes a string as input and creates a human-friendly URL string. This is useful if, for example, you have a blog in which you'd like to use the title of your entries in the URL. Example:
$title = "What's wrong with CSS?";

Code:
$url_title = url_title($title);
// Produces: whats-wrong-with-css
#6

[eluser]Pascal Kriete[/eluser]
Seppo wins.
#7

[eluser]zeedy2k[/eluser]
even better Big Grin

Thanks guys




Theme © iAndrew 2016 - Forum software by © MyBB