PHP string help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Drannon
Forum Newbie
Posts: 4
Joined: Wed Oct 29, 2003 12:49 pm

PHP string help

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;)
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post 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
Drannon
Forum Newbie
Posts: 4
Joined: Wed Oct 29, 2003 12:49 pm

Post 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.
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

try urlencode($string);, it will replace the spaces with %20 which it's it's equivalent
Drannon
Forum Newbie
Posts: 4
Joined: Wed Oct 29, 2003 12:49 pm

Post 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.
Drannon
Forum Newbie
Posts: 4
Joined: Wed Oct 29, 2003 12:49 pm

Post by Drannon »

/bump.

Can anyone help with this?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Post Reply