homer.favenir Posted May 6, 2008 Share Posted May 6, 2008 hi, my string is: $string = 1103 LUCERNE TER\TOLL FREE DIAL '1' & THEN\; but i only need is 1103 LUCERNE TER how can i remove \TOLL FREE DIAL '1' & THEN\ can i use preg_replace? and how? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/104418-solved-how-to-remove-toll-free-dial-1-and-then-in-a-string/ Share on other sites More sharing options...
Daniel0 Posted May 6, 2008 Share Posted May 6, 2008 str_replace("\\TOLL FREE DIAL '1' & THEN\\", '', $string); Quote Link to comment https://forums.phpfreaks.com/topic/104418-solved-how-to-remove-toll-free-dial-1-and-then-in-a-string/#findComment-534537 Share on other sites More sharing options...
homer.favenir Posted May 6, 2008 Author Share Posted May 6, 2008 great! thanks! but i have some strings like \WWW.ARMORATL.COM\ and \TOLL FREE-DIAL \ and so on... how about if the toll free changes? Quote Link to comment https://forums.phpfreaks.com/topic/104418-solved-how-to-remove-toll-free-dial-1-and-then-in-a-string/#findComment-534539 Share on other sites More sharing options...
Daniel0 Posted May 6, 2008 Share Posted May 6, 2008 If you always only need the thing before the first backslash, then you could do: strstr($string, '\\', true); Quote Link to comment https://forums.phpfreaks.com/topic/104418-solved-how-to-remove-toll-free-dial-1-and-then-in-a-string/#findComment-534555 Share on other sites More sharing options...
homer.favenir Posted May 6, 2008 Author Share Posted May 6, 2008 thanks! is this right? 59: $newdata[2] = strstr($olddata[2], '\\', true); 60: $newdata[3] = strstr($olddata[3], '\\', true); 61: $newdata[4] = strstr($olddata[4], '\\', true); there is an error. Warning: Wrong parameter count for strstr() in C:\xampp\htdocs\exceed\index.php on line 59 Warning: Wrong parameter count for strstr() in C:\xampp\htdocs\exceed\index.php on line 60 Warning: Wrong parameter count for strstr() in C:\xampp\htdocs\exceed\index.php on line 61 Quote Link to comment https://forums.phpfreaks.com/topic/104418-solved-how-to-remove-toll-free-dial-1-and-then-in-a-string/#findComment-534565 Share on other sites More sharing options...
Daniel0 Posted May 6, 2008 Share Posted May 6, 2008 Ah, sorry. I didn't realize that the third parameter is added in 5.3 which is not yet released. Try this instead: substr($string, 0, strpos($string, '\\')-1); Quote Link to comment https://forums.phpfreaks.com/topic/104418-solved-how-to-remove-toll-free-dial-1-and-then-in-a-string/#findComment-534566 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.