Page 1 of 1

PHP string help

Posted: Wed Oct 29, 2003 12:49 pm
by Drannon
Ok, I am calling a perl script and getting the output back and storing that in a variable. Here is what the sample output looks like:


210: X.500 Directory 210: Tier 2 Dialup 210: Mail (blah blah blah) 210: TimeManager (blah blah blah) 510: Something else


210 means success and 510 means failiure.

I basically want to separate out each and display it this way:

X.500 Directory Success
Tier 2 Dialup Success
Mail Success
TimeManager Success
Something else Failiure


There could be any number of these in a variable. Is there anyway of doing this without searching for each separate possibility?

Basically search for a code with a colon following it, and then take the string after it, until the next colon or something?


-Thanks

Posted: Wed Oct 29, 2003 1:14 pm
by volka
you might use explode() to get all substrings. If there can be a : within the data (not as field seperator) you're in trouble ;)

Posted: Wed Oct 29, 2003 1:35 pm
by gite_ashish
One quick (& dirty) solution might be --

Code: Select all

<?php

$s = "210: X.500 Directory 210: Tier 2 Dialup 510: some failure stuff 210: Mail
(blah blah blah) 210: TimeManager (blah blah blah) 510: Something else ";

 // if browser based app, use "<br>"
// if command line app, use "\n"
$s2 = str_replace('210:', '<br>SUCESS:', $s);  
$s2 = str_replace('510:', '<br>FAILED:', $s2);

?>

... above outputs --

SUCESS: X.500 Directory
SUCESS: Tier 2 Dialup
FAILED: some failure stuff
SUCESS: Mail (blah blah blah)
SUCESS: TimeManager (blah blah blah)
FAILED: Something else
with one exta space in top and SUCESS/FAILED message at starting of line

Posted: Wed Oct 29, 2003 2:08 pm
by Drannon
Hmm I will try it. But another thing is that I need to pass it through the URL, but what its doing is that it is only sending the first part of it, like 210: x500 directory, not the rest of the string. Any ideas?

Any help is appreciated.

Posted: Wed Oct 29, 2003 2:13 pm
by Cruzado_Mainfrm
try urlencode($string);, it will replace the spaces with %20 which it's it's equivalent

Posted: Thu Oct 30, 2003 7:21 am
by Drannon
OK, but is there anyway to separate them into variables?

Like

$array[1] = "email fail";
$array[2]="caldender success";

And if thats not possible, I can just declare a bunch of variables and do

$email="success"
$calender="fail"

etc..

...

The reason being that I am inserting each success and fail separatly into a mySQL database.

Any help is appreciated.

Posted: Fri Oct 31, 2003 5:47 am
by Drannon
/bump.

Can anyone help with this?

Posted: Fri Oct 31, 2003 7:43 am
by McGruff
You could use strpos() and substr() to process the string. Post whatever code you come up with and we'll take it from there.