473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Parse URI

I want to pull part of the URI out to dictate what is pulled from the
database. For example, I want to control what year data is displayed
with a url like this: http://www.mysite.com/display.php?year=2007

I want to pull out the 2007. I can grab the uri, but what is the best
way to pull out just the 2007?
Nov 15 '07 #1
4 5381
On Nov 15, 10:34 am, mtuller <mitul...@gmail.comwrote:
I want to pull part of the URI out to dictate what is pulled from the
database. For example, I want to control what year data is displayed
with a url like this:http://www.mysite.com/display.php?year=2007

I want to pull out the 2007. I can grab the uri, but what is the best
way to pull out just the 2007?
See parse and parse_url function in PHP manual.
Nov 15 '07 #2
On Thu, 15 Nov 2007 06:34:37 +0100, mtuller <mi******@gmail.comwrote:
I want to pull part of the URI out to dictate what is pulled from the
database. For example, I want to control what year data is displayed
with a url like this: http://www.mysite.com/display.php?year=2007

I want to pull out the 2007. I can grab the uri, but what is the best
way to pull out just the 2007?

$url = 'http://www.mysite.com/display.php?year=2007';
$querystring = parse_url($url,PHP_URL_QUERY);
$querydata = array();
parse_str($querystring, $querydata);
if(isset($querydata['year'])) echo "Year is:".$querydata['year'];

--
Rik Wasmus
Nov 15 '07 #3
On Nov 15, 12:34 am, mtuller <mitul...@gmail.comwrote:
I want to pull part of the URI out to dictate what is pulled from the
database. For example, I want to control what year data is displayed
with a url like this:http://www.mysite.com/display.php?year=2007

I want to pull out the 2007. I can grab the uri, but what is the best
way to pull out just the 2007?
Do you just have a URL in a string or is it the URL of the actual
request? If it's the URL of the request, that value would be in:

$_GET['year']

If it's in a string the other solutions posted here should work.
Nov 15 '07 #4
On Nov 15, 8:19 am, ZeldorBlat <zeldorb...@gmail.comwrote:
On Nov 15, 12:34 am, mtuller <mitul...@gmail.comwrote:
I want to pull part of the URI out to dictate what is pulled from the
database. For example, I want to control what year data is displayed
with a url like this:http://www.mysite.com/display.php?year=2007
I want to pull out the 2007. I can grab the uri, but what is the best
way to pull out just the 2007?

Do you just have a URL in a string or is it the URL of the actual
request? If it's the URL of the request, that value would be in:

$_GET['year']

If it's in a string the other solutions posted here should work.
Yes, it is the URL of the request. LOL I thought it would be harder
than this. I was overthinking it. Thanks.
Nov 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
24
by: | last post by:
Hi, I need to read a big CSV file, where different fields should be converted to different types, such as int, double, datetime, SqlMoney, etc. I have an array, which describes the fields and...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
3
by: Mark | last post by:
How do you parse a currency string to a decimal? I'd like to avoid having to parse the number out, removing the $ manually. That sounds like a hack. There are times that this string will be...
14
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style...
3
by: Bob Rundle | last post by:
I would like to get something like this to work... Type t = FindMyType(); // might be int, float, double, etc string s = "1233"; object v = t.Parse(s); This doesn't work of couse, Parse is...
3
by: Slonocode | last post by:
I have some textboxes bound to an access db. I wanted to format the textboxes that displayed currency and date info so I did the following: Dim WithEvents oBidAmt As Binding oBidAmt = New...
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
2
by: Samuel R. Neff | last post by:
I'm using a quasi open-source project and am running into an exception in double.Parse which is effectively this: double.Parse(double.MinValue.ToString()) System.OverflowException: Value was...
3
by: Peter Duniho | last post by:
I'm sure there's a good explanation for this, but I can't figure it out. I tried using DateTime.Parse() with a custom DateTimeFormatInfo instance, in which I'd replaced the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.