look within a string, cut it down something help?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
soulzllc
Forum Newbie
Posts: 4
Joined: Sat May 06, 2006 9:46 pm

look within a string, cut it down something help?

Post by soulzllc »

ALright im feelin stupid now.. But I cant think of the term for what I am looking for.. so in short..

I wanna take something like

ID=030611
or
ID=030612
or
ID=040610

ultimately what i wanna do is find the first 4 digits or sometime letters in a particular var phrased via URL
but Im havin a bit of trouble there.. I cant remember or think of the function or term for it... so if someone could please help me find my path that would be great, and I appreciate it..

I can think of similar for mirc scripting, and or VB but i lost myself with this one despite me having done it in the past long ago a few times..
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Post by HiddenS3crets »

Based on your post, I think you're thinking of $_GET

Example:

Code: Select all

www.yourdomain.com?id=059491

Code: Select all

<?php
$id = $_GET['id'];

// Returns 059491
echo $id;
?>
soulzllc
Forum Newbie
Posts: 4
Joined: Sat May 06, 2006 9:46 pm

Post by soulzllc »

$_get is the concept yes.. but im looking to take the gotten var and trim it, well not trim it but break it down finding the last couple of of letters/numbers or the first

taking my orginal example...

ID=123456

i want to find the 1234 of the ID, and do something else with the 56 (yes im know I can use 2 var's) but the site im working on is tooooo large to go and reconvert it all to a 2 var structure.. I know what I wanna do is possible.. but I cant remember how I used to do it..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

soulzllc
Forum Newbie
Posts: 4
Joined: Sat May 06, 2006 9:46 pm

Post by soulzllc »

substr() .. is very very close to what I want.. but I dont think I can pull off what I want with it as the set of numbers I am stuck with using range from 5-8 or more numbers.. what i need to ultimately do is snag the ID
which I can do with the $_get, but from there I need to break it down...

substr() does it in a sence but not from what I can gather in the sence I need to do it in..

I wanna break the 5-8 or more numbers down into 2 sets... first 4 will always be one set then the remaining 1-3 or more numbers will be another set.. again I know I can use 2 vars but im stuck with a very large site with little time to redo certain aspects of it, and to convert well over 1,000 hard coded links within pages and convert them to a new system so to speak is not an option I have at the moment concidering the time frame at hand.. soo anyone who can help me wouild be again greatly appreciated..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$v1 = substr($foo, 0, 4);
$v2 = substr($foo, 4);
Works just fine.
soulzllc
Forum Newbie
Posts: 4
Joined: Sat May 06, 2006 9:46 pm

Post by soulzllc »

yes yes it does, thank you soooo much.. im sittin here buttin my head against the wall tired agravated you know the mind frame.. im sittin here thinkin of the most outlandish concept tryin to make it work then you present me this simple little tid bit that works more then perfect, thank you very much...
Post Reply