Jump to content

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;

                    }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.