Stephen68 Posted December 9, 2007 Share Posted December 9, 2007 I'm really new to regex and I'm plan on getting a book on this or a good print out from on line to study. What I need help with right now is just something simple but yet hard for me for some reason. I have a URL say... www.yoururl.com/something/page.php?var=val What I was hoping to get was everything up to the question mark, I will assume that if there was no question mark the regex would grab it all? Anyway any help in this would be great, sorry for posting so soon it's just I need it fairly bad. Stephen Quote Link to comment https://forums.phpfreaks.com/topic/80913-regex-help/ Share on other sites More sharing options...
dsaba Posted December 9, 2007 Share Posted December 9, 2007 without regex you can take only the part to the left of the queryString by using explode() <?php $url = 'www.yoururl.com/something/page.php?var=val'; $splitUrl = explode('?', $url); $newUrl = $splitUrl[0]; echo $newUrl; //if url doesn't have any queryString //same code will still work $url = 'www.yoururl.com/something/page.php'; $splitUrl = explode('?', $url); $newUrl = $splitUrl[0]; echo $newUrl; ?> Quote Link to comment https://forums.phpfreaks.com/topic/80913-regex-help/#findComment-410487 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.