Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Convert String to url friendly string

How can I somehow convert "a 16134 !#¤ toko5 14&!G90 into like a-16134-toko5-14-G90 or something like that, so that it can be used as a part of the url.
Look it up on google preg functions in php :) Just use PHP's documentation you won't learn anything unless you go research it yourself :)
http://cubiq.org/the-perfect-php-clean-url-generator

If you google well enough, someone else has ALWAYS made a function
--

:)

--

Best form of contact is email: [email protected]


use this function:
PHP Code

<?php 
function to_url($text){

    
$text=trim($text);//remove space in first and end    
    
$text= strtr($text,"ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ","aaooeecciiuuynn"); //remove accents
    
$text = preg_replace('/([^.a-z0-9]+)/i', '-', $text);   // remove  special character: other than letters and numbers change it to -
    
$text = strtolower($text); //lowercase
    
return $text;
} 
With the preg_replace() function.
PHP Code

<?php 
$string 
= preg_replace ('/[^a-zA-Z0-9]+/', '-', $string); # replace non-alphanumeric groups with a hyphen. 
put your string in one variable.
make another variable valid char like "abc...xyz.ABC..XYZ012..9".
Check if the char in ur string is contained in valid char.
if yes,put it as it is
else,"-"
Thanks a lot to all of you. I got this solved.
:YEAH!:


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Javascript]  by ♠ɪᴄᴇ♠Apr 26, 2016 08:41 PM 10 249 Apr 26, 2016 08:41 PM
Last Post: ♠ɪᴄᴇ♠
[PHP] by CPAManagerApr 30, 2013 11:19 AM 6 166 Apr 30, 2013 11:19 AM
Last Post: CPAManager
[PHP] by hebrew878Jan 4, 2013 09:47 AM 3 101 Jan 4, 2013 09:47 AM
Last Post: badbrains