crashmaster Posted February 4, 2009 Share Posted February 4, 2009 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 )) Quote Link to comment https://forums.phpfreaks.com/topic/143854-solved-strip-all-special-chars/ Share on other sites More sharing options...
corbin Posted February 4, 2009 Share Posted February 4, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/143854-solved-strip-all-special-chars/#findComment-754852 Share on other sites More sharing options...
crashmaster Posted February 5, 2009 Author Share Posted February 5, 2009 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 =) Quote Link to comment https://forums.phpfreaks.com/topic/143854-solved-strip-all-special-chars/#findComment-754859 Share on other sites More sharing options...
corbin Posted February 5, 2009 Share Posted February 5, 2009 Oh. And no problem. Quote Link to comment https://forums.phpfreaks.com/topic/143854-solved-strip-all-special-chars/#findComment-754862 Share on other sites More sharing options...
crashmaster Posted February 5, 2009 Author Share Posted February 5, 2009 do you see the difference ??)) Quote Link to comment https://forums.phpfreaks.com/topic/143854-solved-strip-all-special-chars/#findComment-754863 Share on other sites More sharing options...
crashmaster Posted February 5, 2009 Author Share Posted February 5, 2009 function mp3URL($var) { preg_replace('/[^a-zA-Z0-9]/', ' ', $var); str_replace(' ', '+', $var); preg_replace('/[ ]+/', '+', $var); return $var; } it doesn't work ((( Quote Link to comment https://forums.phpfreaks.com/topic/143854-solved-strip-all-special-chars/#findComment-754866 Share on other sites More sharing options...
crashmaster Posted February 5, 2009 Author Share Posted February 5, 2009 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; } Quote Link to comment https://forums.phpfreaks.com/topic/143854-solved-strip-all-special-chars/#findComment-754875 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.