Jump to content

String concantonation problem?


A JM

Recommended Posts

I'm trying to concantonate a string with the following and I don't understand why its wrong, can someone help?  :confused:

 

$VEND = "VEND" . "t\" . $row['lastname'] . ", " . $row['firstname'] . "t\t\t\t\t\" . $row['company'] . "t\" . $row['email'] . "t\" . $row['cell'] . ", " . $row['fax'] . "t\t\t\t\t\t\t\t\t\" . "Y" . "t\t\t\t\t\t\t\t\t\t\t\t\t" . "\r\n";

 

A JM,

Link to comment
https://forums.phpfreaks.com/topic/185205-string-concantonation-problem/
Share on other sites

If you use a syntax highlighter, the reason becomes fairly obvious (IMO)...

 

$VEND = "VEND" . "t\" . $row['lastname'] . ", " .$row['firstname'] . "t\t\t\t\t\" . $row['company'] . "t\" .$row['email'] . "t\" . $row['cell'] . ", " . $row['fax'] ."t\t\t\t\t\t\t\t\t\" . "Y" . "t\t\t\t\t\t\t\t\t\t\t\t\t" . "\r\n";

In case you can't see it, the backslash right before the closing string delimiters (") are escaping the character, thus PHP believes that it is not the delimiter and looks for the rest of the string. You can fix the problem by escaping the last backslash, that is to say placing another backslash before it so that PHP knows it's a literal backslash. Having said this I doubt that's actually what you want, why have you got so many t\'s in your code anyway? Surely that can't mean a great deal.

Thanks, I'm trying to create a TAB formatted string... cags, I got a few extra"\" and t's when I double back slashed the t's like the following..

 

$VEND = "VEND" . "t\\" . $row['lastname'] . ", " . $row['firstname'] . "t\t\t\t\t\\" . $row['company'] . "t\\" . $row['email'] . "t\\" . $row['cell'] . ", " . $row['fax'] . "t\t\t\t\t\t\t\t\t\\" . "Y" . "t\t\t\t\t\t\t\t\t\t\t\t\t\\" . "\r\n";

 

I got the following error when trying your example otuatail:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /myweb.com/QB.php on line 174

 

$VEND = "VEND" . "t\  $row['lastname'] , $row['firstname'] t\t\t\t\t\ $row['company'] t\ $row['email'] t\ $row['cell'] ,  $row['fax'] t\t\t\t\t\t\t\t\t\ Y t\t\t\t\t\t\t\t\t\t\t\t\t\r\n";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.