Be a Supporter!

having a semi collin in a variable?

  • 438 Views
  • 9 Replies
New Topic Respond to this Topic
blah569
blah569
  • Member since: Jan. 18, 2005
  • Offline.
Forum Stats
Member
Level 25
Programmer
having a semi collin in a variable? 2006-12-03 18:14:18 Reply

How can I do that? Example:

$variable =
"
some code goes here...;
some more here;
";

I hope you understand. Please help. Thanks.


BBS Signature
Gutya
Gutya
  • Member since: Nov. 27, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to having a semi collin in a variable? 2006-12-03 18:21:21 Reply

In PHP?

You can have a semi-colon in strings.

blah569
blah569
  • Member since: Jan. 18, 2005
  • Offline.
Forum Stats
Member
Level 25
Programmer
Response to having a semi collin in a variable? 2006-12-03 18:22:21 Reply

No... you will get a error. It will day like "unexpected T_END" if you have it in a string.


BBS Signature
Jessii
Jessii
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 36
Movie Buff
Response to having a semi collin in a variable? 2006-12-03 18:28:21 Reply

Can't you put it in quotes so that it comes up as text?

blah569
blah569
  • Member since: Jan. 18, 2005
  • Offline.
Forum Stats
Member
Level 25
Programmer
Response to having a semi collin in a variable? 2006-12-03 18:32:12 Reply

this is what I am trying to do:

$code =
"
$sql_un = '$un';
$sql_pw = '$pw';
$sql_host = '$host';
$sql_db = '$db';

mysql_connect('$sql_host','$sql_pw','$sql_pw' )or die('ZarginBB Error #1<br><br>Can't connect to the database. Ask one of the admins for help.');
mysql_select_db('$sql_db')or die('ZarginBB Error #2<br><br>Can't select the database. Contact the admin.");
";


BBS Signature
Gutya
Gutya
  • Member since: Nov. 27, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to having a semi collin in a variable? 2006-12-03 18:39:11 Reply

Why does all that need to go into a string?

And it's better to do multi-line strings with heredoc.

Example:

$string = <<<IDENTIFIER

String
contents
here
you can even ouput $variables without escaping the string.

INDENTIFIER;

echo $string;

Where IDENTIFIER tells PHP where to start and end the string, it can be anything you want, but I usually make it upper-case to avoid confusion.

blah569
blah569
  • Member since: Jan. 18, 2005
  • Offline.
Forum Stats
Member
Level 25
Programmer
Response to having a semi collin in a variable? 2006-12-03 18:57:39 Reply

At 12/3/06 06:39 PM, Gutya wrote: Why does all that need to go into a string?

And it's better to do multi-line strings with heredoc.

Thanks. I will try that =).


BBS Signature
DFox
DFox
  • Member since: Aug. 9, 2003
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to having a semi collin in a variable? 2006-12-03 19:12:31 Reply

$code =
'
$sql_un = \'$un\';
$sql_pw = \'$pw\';
$sql_host = \'$host\';
$sql_db = \'$db\';

mysql_connect(\'$sql_host\',\'$sql_pw\',\'$sq l_pw\' )or die(\'ZarginBB Error #1<br><br>Can\'t connect to the database. Ask one of the admins for help.\');
mysql_select_db(\'$sql_db\')or die(\'ZarginBB Error #2<br><br>Can\'t select the database. Contact the admin.");
';
?


BBS Signature
henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to having a semi collin in a variable? 2006-12-04 02:59:35 Reply

Have you heard of functions? You sure does not act like you have.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to having a semi collin in a variable? 2006-12-04 03:40:54 Reply

At 12/4/06 02:59 AM, henke37 wrote: Have you heard of functions? You sure does not act like you have.

how is that relevant? i just guess i missed the point...


BBS Signature