Ghostspirit
asked on
Copy part of string
Please read the comment inside the script
<?php
$Messagecode="
100 Can't read
200 Can write
300 Can't write
400 Can write
500 Can't delete
600 Can Delete
700 Upload okay
800 Bad Username.
";
$Code=100;
//some script here.
//something like, look inside the $Messagecode, if the $Code is match on of the line in the $Messagecode then copy that line. and print it.
if(isset($Code) && $Code =='100'){
//copy part of the string, the result should be Can't read
}
if(isset($Code) && $Code =='200'){
//copy part of the string, the result should be Can write
}
****IF NOT MATCH ANY OF THOSE CODE,
Echo "Code not found";
?>
<?php
$Messagecode="
100 Can't read
200 Can write
300 Can't write
400 Can write
500 Can't delete
600 Can Delete
700 Upload okay
800 Bad Username.
";
$Code=100;
//some script here.
//something like, look inside the $Messagecode, if the $Code is match on of the line in the $Messagecode then copy that line. and print it.
if(isset($Code) && $Code =='100'){
//copy part of the string, the result should be Can't read
}
if(isset($Code) && $Code =='200'){
//copy part of the string, the result should be Can write
}
****IF NOT MATCH ANY OF THOSE CODE,
Echo "Code not found";
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The reason I listed my codes by lines is because my script is reading those values from a file.
Is there any alternative choice?
100 Can't read
200 Can write
300 Can't write
400 Can write
500 Can't delete
600 Can Delete
700 Upload okay
800 Bad Username.
Is there any alternative choice?
100 Can't read
200 Can write
300 Can't write
400 Can write
500 Can't delete
600 Can Delete
700 Upload okay
800 Bad Username.
ASKER
Script error
seem like steelseth12 's script is having a big bug
The script only delete the last line
RESCUE ME HERE
seem like steelseth12 's script is having a big bug
The script only delete the last line
RESCUE ME HERE
Ghostspirit what do you mean DELETE the last line ? Please explain more
ASKER
my bet,
I mean detect the last line which is the "800 Bad Username."
If I change the $Code to a different number, the script will not able to dectect.
for example $Code=600;
I mean detect the last line which is the "800 Bad Username."
If I change the $Code to a different number, the script will not able to dectect.
for example $Code=600;
sorry small mistake ..
change
if(preg_match("/($Code).*? \n$/",$Mes sagecode,$ match)) {
with
if(preg_match("/($Code).*? \n/",$Mess agecode,$m atch)) {
change
if(preg_match("/($Code).*?
with
if(preg_match("/($Code).*?
ASKER
Thank you very
blink blink A++
blink blink A++
Open in new window