Jump to content

regex help


Stephen68

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/80913-regex-help/
Share on other sites

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;
?>

Link to comment
https://forums.phpfreaks.com/topic/80913-regex-help/#findComment-410487
Share on other sites

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.