![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Living inside your head.
Industry Role:
Join Date: Dec 2002
Location: In your AirBNB
Posts: 20,468
|
Some PHP help, please?
So I have this array like this
Code:
[location] => 2020-10-16 04:08PM -0700 City: Las Vegas Region: Nevada Zip Code: 89149 Code:
$city = 'Las Vegas'; $region = 'Nevada'; $zipcode = '89149'; ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Quote:
Hey, I just woke up so can't write the code but I just go through and parse it out based on the words. something along the lines of: $location='2020-10-16 04:08PM -0700 City: Las Vegas Region: Nevada Zip Code: 89149'; $location=strtolower($location); $city=substr($location,strpos($location,'city')+4) ; $city=substr($city,0,strpos($city,'region'); $region=substr($location,strpos($location,'region' )+6); $region=substr($region,0,strpos($region,'region'); $zip=substr($location,strpos($location,'zip code')+8); There is probably a more elegant way but like I said, I just woke up ;p
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Living inside your head.
Industry Role:
Join Date: Dec 2002
Location: In your AirBNB
Posts: 20,468
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
$location="2020-10-16 04:08PM -0700
City: Las Vegas Region: Nevada Zip Code: 89149"; $replace= array("City: ","Region: ","Zip Code: "); $location = str_replace($replace,"",$location); $arr = explode("\n",$location); $city = trim($arr[1]); $region = trim($arr[2]); $zipcode = trim($arr[3]);
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
It's to offset the number of characters but it's wrong, because he didn't factor in the : and the space after it. He also left out two )'s
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
Another way if the order isn't identical each time.
<?php $location="2020-10-16 04:08PM -0700 City: Las Vegas Region: Nevada Zip Code: 89149"; $location = explode("\n",$location); unset($location[0]); foreach($location as $i) { $out = explode(":",$i); $dataOut[trim($out[0])] = trim($out[1]); } print_r($dataOut); Array ( [City] => Las Vegas [Region] => Nevada [Zip Code] => 89149 )
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Quote:
However if you are doing an array it is probably more like this: $location=array('2020-10-16 04:08PM -0700 City: Las Vegas Region: Nevada Zip Code: 89149', '2020-10-16 04:08PM -0700 City: Las Vegas2 Region: Nevada2 Zip Code: 89150', '2020-10-16 04:08PM -0700 City: Las Vegas3 Region: Nevada3 Zip Code: 89151', '2020-10-16 04:08PM -0700 City: Las Vegas4 Region: Nevada4 Zip Code: 89152'); $newlocation=array(); foreach($location as $loc) { $city=substr($loc,strpos($loc,'city')+5); $newlocation[]['city']=substr($city,0,strpos($city,'region')); $region=substr($loc,strpos($loc,'region')+7); $newlocation[]['region']=substr($region,0,strpos($region,'region')); $newlocation[]['zip code']=substr($loc,strpos($loc,'zip code')+9); } var_dump($newlocation); ------------------------- And that one doesn't leave off the )'s and it assumes that the order of the vars is the same. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Living inside your head.
Industry Role:
Join Date: Dec 2002
Location: In your AirBNB
Posts: 20,468
|
Thanks guys, I've got enough here to get it done now
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Too lazy to set a custom title
Industry Role:
Join Date: Dec 2004
Location: Happy in the dark.
Posts: 92,999
|
__________________
FLASH SALE INSANITY! deal with a 100% Trusted Seller Buy Traffic Spots on a High-Quality Network 1 Year or Lifetime — That’s Right, Until the Internet Explodes! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
I have a plan B
Industry Role:
Join Date: Aug 2004
Location: Seattle - Miami - St Kitts
Posts: 5,501
|
I wouldn't try anything before coffee.
__________________
CryptoFeeds |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
There's a java joke in here somewhere..
![]()
__________________
![]() I've referred over $1.7mil in spending this past year, you should join in. ![]() ![]() I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years.. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Just Doing My Own Thing
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
|
Don't Java before Java? - I know it's PHP but it's the best I could do - I haven't had any coffee yet...
__________________
- Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Just wait till i'm in charge around here. You are all going to regret making fun of me.
Dammit. . |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 | |
Just Doing My Own Thing
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
|
Quote:
![]() I love you even though you can't count to 6..... If you get stuck again it's the number of fingers you have on your left hand... . Sorry again, I'm in one of those moods.....
__________________
- Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Quote:
I debugged it and found the issues before K0nr4d said anything dammit. Fuckers picking on me. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
I need a beer
![]() Industry Role:
Join Date: Jun 2002
Location: ♠ Toiletville ♠
Posts: 133,919
|
Ballers hire people to do that
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 |
Just Doing My Own Thing
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
|
I disagree - Real BALLERS come to GFY and ask - That's why they are BALLERS - You could pay a grand for that info, a grand you can invest - Maybe if you are millions in you can waste money like that...
Lets see - I could pay a grand for some company to come back to me a week later - Or post on GFY and get the answer within a few hours - A few years ago it would have been minutes..... I was going to do a Trump joke - I would get told off though...
__________________
- Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 | |
I need a beer
![]() Industry Role:
Join Date: Jun 2002
Location: ♠ Toiletville ♠
Posts: 133,919
|
Quote:
![]()
__________________
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 |
Just Doing My Own Thing
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
|
I wipe my ass with your 2 cents...
Sorry Mr Pheer - Totally derailed your thread..... Spunky - You apolligise as well...
__________________
- Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 |
frc
Industry Role:
Join Date: Jul 2003
Location: Bitcoin wallet
Posts: 4,664
|
this reminds my why i switched to nodejs from php, makes this like this much simpler
__________________
Crazy fast VPS for $10 a month. Try with $20 free credit |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#21 |
Living inside your head.
Industry Role:
Join Date: Dec 2002
Location: In your AirBNB
Posts: 20,468
|
Yeah and I switched to Python as was blown away by it's simplicity. But sometimes shit just has to be done in PHP and I can't remember much of it because I hardly ever write it anymore.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#22 | |
Living inside your head.
Industry Role:
Join Date: Dec 2002
Location: In your AirBNB
Posts: 20,468
|
Quote:
My kid is in for his Bachelor's in Computer Science at UNLV and they have him in Calculus 2 and I'm like, wtf you need that for? They also don't teach him anything except for C programming. When I ask him for PHP help he tells me "that's web shit, dude" |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#23 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Quote:
Lol at the C attitude. A friend of mine has a kid who is self taught C but unemployed. I told him I could throw him some PHP work and he was like "I only do C". My reply was "How much you makking doing that?". He didn't like that. Not putting down C programmers at all there. I program in C when I have to. I also do some python, hell I still do foxpro, cobol, VB, whatever language is needed. However, if you want to work for yourself, the easiest work to find is PHP because so much of the web stuff is written in PHP, that simple, ya know? .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#24 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
No one ever said PHP was a good programming language...
![]()
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#25 |
Just Doing My Own Thing
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
|
From you that's fucking hilarious!..
__________________
- Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#26 |
Too lazy to set a custom title
Join Date: Jan 2002
Location: Holland
Posts: 9,870
|
Looks like json, maybe you should ask for all the data.
__________________
Don't let greediness blur your vision | You gotta let some shit slide icq - 441-456-888 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#27 |
So Fucking Banned
Industry Role:
Join Date: Apr 2001
Location: the beach, SoCal
Posts: 107,090
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#28 |
I have a plan B
Industry Role:
Join Date: Aug 2004
Location: Seattle - Miami - St Kitts
Posts: 5,501
|
When I was in school the only option was Fortran. So try some of that programming, you could work for NASA or Elon Musk. Of course, you're going to need more than one cup of coffee!
__________________
CryptoFeeds |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#29 | |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
Quote:
![]() I did COBOL for a little bit, too. Wasn't paying enough.
__________________
![]() I've referred over $1.7mil in spending this past year, you should join in. ![]() ![]() I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years.. ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#30 |
making it rain
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 22,009
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#31 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
Quote:
I spent all my free time in the computer lab that semester, lol. One test, he brought to me in the lab because I had somehow forgotten about it and missed class that night. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#32 |
Industry Role:
Join Date: Mar 2003
Location: San Diego
Posts: 32,174
|
![]() ![]()
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#33 | |
So fuckin' bored
Industry Role:
Join Date: Jun 2003
Posts: 32,381
|
![]() Quote:
Code:
preg_match('/City: (.*?)\n.*?Region: (.*?)\n.*?Zip Code: (.*?)$/s', $location, $matches); array_shift($matches); list($city, $region, $zipcode) = $matches; ![]() P.S. Some people say my code sux. That because it's mostly unreadable like the one above. They write for people, I write for machines. This is why it looks so strange, but it much more compact and faster than the code, most coders are used to produce (with all those classes etc). PHP is not C++ and the server resources are very limited.
__________________
Obey the Cowgod |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#34 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
While I will admit - short, elegant, you are firing up the regex engine. I actually timed the execution for shits to see which works fastest (adding an echo of the output at the end for fairness in each):
0.0002028942108 (konrad v1) 0.0002288818359 (konrad v2) 0.0003898143768 (cyberseo) 0.0011749267578 (sarettah) We are of course talking about 1/10000ths of a second difference here ![]()
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#35 |
So fuckin' bored
Industry Role:
Join Date: Jun 2003
Posts: 32,381
|
Actually not
![]() So, if you want to do a string replace or find a fixed text, course you will be using simple string functions. But if you need to find some brain-breaking pattern, you will be using regexp. That's what it designed for. E.g. is the qsort algorithm the fastest and optimized one? You may say "not", because we can find lot of cases when it will be slow like a turtle, but... in general cases it faster that other more specific sorting algos. The same applies to regexp. Sometimes (in simplest cases) it really slower, but in general cases when you work with patterns, it's the fastest method. Don't you agree? ;)
__________________
Obey the Cowgod |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#36 | |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
Quote:
It is interesting though how there's so many ways to do it and the huge variance in execution speed with one way taking 5-6x as long to execute despite basically being exactly the same thing.
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#37 |
Living inside your head.
Industry Role:
Join Date: Dec 2002
Location: In your AirBNB
Posts: 20,468
|
Regex makes my head hurt. You fuck up one character and you've opened your script to shit like php injection hacks. Thanks for the code though
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#38 |
I'm still broke.
Industry Role:
Join Date: Jul 2008
Location: WildWildWest
Posts: 3,084
|
It's good to see k0nr4d helping people
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |