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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping long complex strings contained in a div

Status
Not open for further replies.

maslett

Technical User
Mar 11, 2004
121
GB
Hi,

I'm trying to keep a long string contained in a div - the problem is I'm not defining the string and it may contain all types of quotes and other control characters (the string is computer generated)

Here's an example:

Code:
{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}

The TGML 'code' tags handle this perfectly (as seen above) - that's what I need to do!

The only thing guaranteed about the string is that it's surrounded by curly brackets.

Cheers.
m@

 
Hi

Use heredoc :
Code:
$string_with_div_content=<<<ENDOFTEXT
[small]{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}[/small]
ENDOFTEXT;
Or am I misunderstanding something ?

Feherke.
 
That looked promising but it didn't work.

Here's the code I used - example1 displays it in html then example2 uses your suggestion:
Code:
<div class="textleft">
Example1:<br>
{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}
<br><br>
Example2:<br>
<?php
$mystring=<<<ENDOFTEXT
{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}
ENDOFTEXT;
echo $mystring;
?>
</div>

...and here's the output:
Code:
Example1:
{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}

Example2:
{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}

...for the record - here's the original string:
Code:
{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}

It seems that the string in html (example1) is displayed correctly - kinda makes sense as quotes mean something in php.

To clarify the problem - the string is not contained in its div container - you can see the examples above on my site here (just my personal website)
 
Hi

Ah, you have some dollar signs ( $ ). Then you need nowdoc :
Code:
$string_with_div_content=<<<[COLOR=red pink]'[/color]ENDOFTEXT[COLOR=red pink]'[/color]
[small]{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}[/small]
ENDOFTEXT;

Feherke.
 
Weird - I put the single quotes in:

Code:
$mystring=<<<'ENDOFTEXT'
{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}
ENDOFTEXT;
echo $mystring;

...and got this:
Code:
Parse error: syntax error, unexpected T_SL in /home/maslett/aslettnet/geek/ebox.inc.htm on line 17

Looking at the source around line 17 (line 17 in bold)...
Code:
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>[URL unfurl="true"]www.aslett.net</title>[/URL]
    <link href="style.css" rel="stylesheet" type="text/css">
	<!--[if IE]>
	<link href="iehacks.css" rel="stylesheet" type="text/css">
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="niftyCorners.css">
	<link rel="stylesheet" type="text/css" href="niftyPrint.css" media="print">

	<link rel="shortcut icon" href="[URL unfurl="true"]http://www.aslett.net/favicon.ico">[/URL]
	<script type="text/javascript" src="nifty.js"></script>
	<script type="text/javascript">
	[b]window.onload=function(){[/b]
	if(!NiftyCheck())
	   return;
	}
	</script>
</head>

I have a feeling this is going to go off on a tangent...
 
(message to self - read the error message)

The problem isn't line 17 in the source - it's line 17 in the include file. Here's the whole include file mentioned in the error message - line 17 is in bold:
Code:
<p class="boxtitle">electric-box - a VERY addictive puzzle game</p>
<div class="textleft">electric-box is a VERY VERY addictive online puzzle game.  The idea is to get the electricity from the power box to the target box using steam, light, lasers, water and wind.  Sounds boring? NO!!  Sounds easy? NO!! Some of the levels can take several hours to work out - and then you want to 'try just one more'...  It is very, very addictive - be warned!<br><br>
The game originally comes with 15 levels (the early ones teach you what to do) but anyone can design their own levels - these can be *really* tough.  Scroll down (under the picture) for more levels.
<br><br>
<div style="text-align: center;"><a href="[URL unfurl="true"]http://www.candystand.com/play.do?id=18463"[/URL] target="_blank">Click here to play electric-box</div>
</div>
<div style="text-align: center;"><br><br><img src="images/box.gif" border="0"></a><br><br></div>

<div class="hr" style="background: #1b1b1b url(../images/hr2.gif) repeat-x scroll center;"><hr/></div>

<div class="textleft">
Example1:<br>
{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}
<br><br>
Example2:<br>
<?php
[b]$mystring=<<<'ENDOFTEXT'[/b]
{"0$#0"$0D%2%&0"'1/(0#,0|/0920|@0DB0#D2)F0DJ0DK2)M0"O0#P0DT0#U0#V0#X0#Y0#Z0#]3D^0#`0)a2&b0"c0"d0$e2Dg2Dh0Aj0Dk0)l0Dn0Do2Dq1Dr0"s1Dt0"u1Dv0"w1Dx0"y0D~(#/43)/3~!0"B+?,@-.5?6@7+?G@GA6I(J(K(}
ENDOFTEXT;
echo $mystring;
?>
</div>
 
HaHa - you're writing replies quicker than I can!

I'll have a word with my web host - nowdoc seems to be the answer.

Will update the thread if I can.

Thanks for your help!

Regards,
m@
 
can't you just use heredoc and escape the $ signs with a backslash?
 
I guess that could work but it's not a permanent fix for the problem. I had a look at the source code for this page and tek-tips use a css class for their code tags (which do exactly what I'm after) so I'm going to the css forum.

Cheers anyway!
m@
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top