Jump to content

[SOLVED] STRIP ALL SPECIAL CHARS


crashmaster

Recommended Posts

Hi there,

 

does anyone know, how to strip all special chars from string ??

 

for example i have $str : Evol Intent, Ewun & Vicious Circle - Odd Number

 

I need output like this "Evil+Intent+Ewun+Vicious+Circle+Odd+Number"

 

Thank you ))

Link to comment
https://forums.phpfreaks.com/topic/143854-solved-strip-all-special-chars/
Share on other sites

preg_replace('/[^a-zA-Z0-9]/', '', $var);

 

 

And then str_replace(' ', '+', $var);

 

 

Just wondering, why are you using +'s?  If you're doing something with a URL, you might just want urlencode().

 

 

 

By the way, if you want two spaces to make 1 +, you will need to do:

 

preg_replace('/[ ]+/', '+', $var);

No, URLENCODE is not suitable for me.

 

I've found big database of the Mp3. I have a web page (www.dnbstep.cz); where users can add their videos and also add track name, which they'd used in the video. I make from TRACKname - url which looks like www.vpleer.ru/?q=[trackname]  - but the problem is:

 

if Trackname contains special chars - it couldn't find proper mp3.

 

Trackname: Evol Intent, Ewun & Vicious Circle - Odd Number

 

Just try this URL: http://www.vpleer.ru/?q=Evol+Intent%2C+Ewun+%26+Vicious+Circle+Odd+Number

 

And try this one: http://www.vpleer.ru/?q=Evol+Intent+Ewun+Vicious+Circle+Odd+Number

 

 

btw" thx for help =)

function mp3URL($var) {
                      preg_replace('/[^a-zA-Z0-9]/', ' ', $var);
                      str_replace(' ', '+', $var);
                      preg_replace('/[ ]+/', '+', $var);
                      return $var;
}

 

it doesn't work (((

It's ok ! I have fixed this function ))

 

                    function mp3URL($var) {

                      $var = trim($var);

                      $var = str_replace(' ', '+', $var);

                      $var = preg_replace('/[^a-zA-Z0-9\+]/', '', $var);

                      $var = preg_replace('/[\+{1,100}]+/', '+', $var);

                      return $var;

                    }

Archived

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

×
×
  • Create New...

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.