Does anyone know how I could parse out a string?
Let's say I had the string "The best player is Kanag and his level is 1."
Now let's say I get this string from a file and want to only print the name of the person, in this case it's Kanag. What all would I need to do to get the name alone? Seeing as PHP has no specific types, I haven't really seen a way to run through a string and change it or even compare them.
Any help is appreciated.
Zorth.
Parsing a String
Moderator: General Moderators
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
[php_man]str_replace[/php_man]
Code: Select all
$string = "~Kanag More info *Extra info";
$string = str_replace("~","",$string);- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
now that you have had some time to play with this, maybe it is time to try regular expressions?
http://www.php.net/manual/en/pcre.pattern.syntax.php
Then you get some real power at your fingertips.
Here's an example:
viewtopic.php?p=113982#113982
http://www.php.net/manual/en/pcre.pattern.syntax.php
Then you get some real power at your fingertips.
Here's an example:
viewtopic.php?p=113982#113982