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
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
Share on other sites

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.