Shoutbox

[PHP] Regular expressions and Status2FTP - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [PHP] Regular expressions and Status2FTP (/showthread.php?tid=61173)

[PHP] Regular expressions and Status2FTP by Matti on 06-25-2006 at 08:17 AM

Yes, me again. :P

I just downloaded and installed Status2FTP, and I immediatly fell in love with it. :) It does what it has to do, and now I want to use it in my signature, as replacement for Web2Messenger.

This means that I have to replace this:

code:
<Details>
<Username>[c=1]<simply[b]_me>[/b][/c=12]</Username>
<PSM><:o) Messenger Plus! [c=7]Live[/c] is arrived! <:o)</PSM>
<Status>Online</Status>
</Details>
into this:
code:
$nick = "[c=1]<simply[b]_me>[/b][/c=12]";
$psm = "<:o) Messenger Plus! [c=7]Live[/c] is arrived! <:o)";
$status = "Online";
So far, I managed to create a function called getXMLData($i) to return the value for $nick, $psm and $status:
code:
function getXMLData($i) {
global $content2;
$data = str_replace(array("<Details>","</Details>"), "", $content2);
$data0 = preg_replace("/<Username>(.*?)<\/Username>/","\\1", $data);
$data1 = preg_replace("/<PSM>(.*?)<\/PSM>/","\\1", $data);
$data2 = preg_replace("/<Status>(.*?)<\/Status>/","\\1", $data);
eval("return \$data$i;");
}
$content2 is the variable containing the XML file, but unfortunaly it doesn't works like I wanted. As you can see, it only drops the <Username> and </Username> tags, where it has to drop these tags and everything before and behind it. And with my small knowledge of regular expressions, I'm back to ask the Messenger Plus! Live community. :)

Any replies or questions are more than welcome! ;)
RE: [PHP] Regular expressions and Status2FTP by Matti on 06-25-2006 at 08:25 AM

Woops! Already solved! :P

code:
//Get the XML data and return it
function getXMLData($i) {
    global $content2;
    $data = str_replace(array("<Details>","</Details>"), "", $content2);
    $data0 = preg_replace("/^<Username>(.*?)<\/Username>(.*?)$/","\\1", $data);
    $data1 = preg_replace("/^(.*?)<PSM>(.*?)<\/PSM>(.*?)$/","\\2", $data);
    $data2 = preg_replace("/^(.*?)<Status>(.*?)<\/Status>(.*?)$/","\\2", $data);
    eval("return \$data$i;");
}
Heh... well, thanks for reading. :)
RE: [PHP] Regular expressions and Status2FTP by Eljay on 06-25-2006 at 08:28 AM

First of all thanks for loving my script :P

Secondly, why do it that way when you can use SimpleXML (PHP5 only)

code:
<?php
$xml = simplexml_load_file('details.xml');
$Username = $xml->Username;
$PSM = $xml->PSM;
$Status = $xml->Status;
?>

RE: [PHP] Regular expressions and Status2FTP by -dt- on 06-25-2006 at 08:29 AM

Insted of eval you could of used variable varibles
http://php.net/language.variables.variable

:-/ you shouldnt preg_replace that , either use simplexml (like eljellybeanfishdog said) or use preg_match and use its matches variable to extract the results

http://php.net/preg_match


RE: [PHP] Regular expressions and Status2FTP by Matti on 06-25-2006 at 09:16 AM

quote:
Originally posted by Eljay
code:
$xml = simplexml_load_file('details.xml');
$Username = $xml->Username;
$PSM = $xml->PSM;
$Status = $xml->Status;

Hmm... it seems like that XML thing doesn't work too great. Let's see...
quote:
Originally posted by Mattike's PHP Info
PHP Version 4.4.2
Doooh... :P
quote:
Originally posted by -dt-
or use preg_match and use its matches variable to extract the results
Can you give me an example? (A)


BTW, still didn't found a solution to strip the ·$(color) tags... :(
code:
$string = preg_replace("/·\$[0-9]{1,2}/", "", $string);
[OFFTOPIC]300th post! :D[/OFFTOPIC]
RE: [PHP] Regular expressions and Status2FTP by Death.Knight on 11-06-2006 at 04:09 AM

I'm interested by your plugin eljay! But i don't know php scripting very well.. Mattike can i see an example of the index.php please?


RE: [PHP] Regular expressions and Status2FTP by NiteMare on 11-06-2006 at 04:39 AM

lets pressure Eljay to continue develoupment, there are a few bug in it still, and he says it could be better:P


RE: [PHP] Regular expressions and Status2FTP by Eljay on 11-06-2006 at 05:30 PM

quote:
Originally posted by NiteMare
lets pressure Eljay to continue develoupment, there are a few bug in it still, and he says it could be better:P

why dont you nagging people feck off :P
RE: [PHP] Regular expressions and Status2FTP by NiteMare on 11-06-2006 at 05:32 PM

quote:
Originally posted by Eljay
quote:
Originally posted by NiteMare
lets pressure Eljay to continue develoupment, there are a few bug in it still, and he says it could be better:P

why dont you nagging people feck off :P
i can't make sence of that sentance:P
RE: [PHP] Regular expressions and Status2FTP by Eljay on 11-06-2006 at 05:36 PM

quote:
Originally posted by NiteMare
quote:
Originally posted by Eljay
quote:
Originally posted by NiteMare
lets pressure Eljay to continue develoupment, there are a few bug in it still, and he says it could be better:P

why dont you nagging people feck off :P
i can't make sence of that sentance:P

likewise... :refuck: