Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Regular Expressions - Pulling a String out of a String - Help?
Old 03-06-2009, 05:12 AM Regular Expressions - Pulling a String out of a String - Help?
Jaryth000's Avatar
Skilled Talker

Posts: 59
Name: Jaryth
Location: Canada
Trades: 0
So, slowly learning more and more PHP... once and a while coming across stuff that talks about Regular Expressions... and every time I've seen it, or gone to try to learn it, its just confused the hell out of me. For some reason I just cant rap my mind around it.

So Im coming here for help. I have colon separated paired values... and I want to be able to remove one of the pairs, from somewhere in the string.
These values are of a 'Player' and there 'Character'. Such that:
Jaryth:Tarrax:James:Alex:Raymond:Kid
Jaryth, James and Raymond are all 'Players' and Tarrax, Alex and Kid are their respective 'Characters'.

Basicaly what Im looking to do, is to have the above string, go in, remove one of the Player:Character pairs, and return the modifed string.
Im guessing its going to look SOMETHING like the following:

PHP Code:
function pullout($string,$out){
preg_match($String, ^%**&^!%^><^^<>^ $out);
}
$string "Jaryth:Tarrax:James:Alex:Raymond:Kid";
$out "James:Alex"
$result pullout($string,$out);
//This would... somehow return the string "Jaryth:Tarrax:Raymond:Kid" 
And I just cannot grasp Regular Expressions for the life of me... (hence the randomness). So would anyone be able to help me by creating the expression I would need?
__________________

Please login or register to view this content. Registration is FREE
My personal website
-Jaryth (UID590)

Last edited by Jaryth000; 03-06-2009 at 05:13 AM.. Reason: changes the randomness so it did not break the Highlightin.
Jaryth000 is offline
Reply With Quote
View Public Profile Visit Jaryth000's homepage!
 
 
Register now for full access!
Old 03-06-2009, 06:33 AM Re: Regular Expressions - Pulling a String out of a String - Help?
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
PHP Code:
function pullout($string,$out){
$string str_replace($out,"",$string); // Remove the $out from $string
$string preg_replace("/[:]{2,}/",":",$string); // Replace any occurence of multiple colons by a single colon.

Not tested, yet.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 03-06-2009, 12:07 PM Re: Regular Expressions - Pulling a String out of a String - Help?
Jaryth000's Avatar
Skilled Talker

Posts: 59
Name: Jaryth
Location: Canada
Trades: 0
Woot, you've made my morning sir, I thank you.
In my tired state, it took me like 15 minutes of playing with it before I realized why it wasn't working XD. I had the function going... but for some reason it wasn't working... till I realized there was no return set, and $string wasn't a global.

in the end the this worked like a charm:

PHP Code:
function pullout($string,$out){
$string str_replace($out,"",$string); // Remove the $out from $string
$string preg_replace("/[:]{2,}/",":",$string); // Replace any occurence of multiple colons by a single colon.
return trim($string":");
}

//(As a note, that last trim there is to remove any trailing colons, like if the last pair was removed) 
Thank you very much for the expression! Maybe RegEx isnt as complicated as I though... hmm..

Talku++!
__________________

Please login or register to view this content. Registration is FREE
My personal website
-Jaryth (UID590)

Last edited by Jaryth000; 03-06-2009 at 12:12 PM.. Reason: Fixed note... *Facepalm*
Jaryth000 is offline
Reply With Quote
View Public Profile Visit Jaryth000's homepage!
 
Reply     « Reply to Regular Expressions - Pulling a String out of a String - Help?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28089 seconds with 12 queries