Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stripping up to 26 slashes 1

Status
Not open for further replies.

superjett

MIS
Jun 18, 2004
62
US
I've tried many ways and searched for other approaches, but am stumped other than the brute force approach on this one.

I have a string variable coming out of a PLC (industrial control processor) that uses \00 as a filler character. That gets stored in MSSQL2000. That is not a problem but when I want to display it, I would like to take everything off the end of the actual name so it looks right.

ex.
GILSONITE\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00

The problem I'm having is \ is a php identifier and using it in a str_replace causes problems. I can take the 00's out and leave the slashes then run up to 7 stripslashes to chop them off but I have 6 variables to work with and that would be silly coding IMO.

Any other suggestions? Or, should I look into mssql and see if I can do the formatting there?
 
Have you tried:
Code:
$test = 'GILSONITE\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00'
$test = str_replace('\\00','',$test);
echo $test;

To replace a single '\' you have to quote it with another '\', so you use '\\'.

Ken
 
You're exactly right and it makes sense after your response, no idea why I didn't see it.

I was using
Code:
$dmaterial = stripslashes(stripslashes(stripslashes(stripslashes(stripslashes(str_replace("00", "", $row['dmaterial']))))));

Hideous!

Thanks.
 
You can also use:
Code:
$test = trim($test,'\\00');

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top