PDA

View Full Version : t string error?



boxxertrumps
12-10-2006, 03:38 PM
the code i will be using to display/store the info in my blog is
<?php

$blog[] = array(title1,date1,entry1)
$blog[] = array(title2,date2,entry2)
$blog[] = array(title3,date3,entry3)

foreach ($blog as $entry)
{echo "<hr /><h3>". $entry[1] ."</h3><br />
<date>".entry[2]."</date><br />
<div class=\"list\">". entry[3] ."</div>"
}
?>

but i got the error


Parse error: parse error, unexpected T_VARIABLE in C:\UTILITIES\Webserv\Abyss Web Server\htdocs\blog.php on line 4

is is because i tried to put an array inside an array?

thetestingsite
12-10-2006, 03:44 PM
I noticed you do not have any semicolons to end the lines. The likely cause of this message is because of this. If the above code is just a copy, and you simply forgot to place the semicolons in the post, then thats not the reason; otherwise, try putting the semicolons at the ends of the lines. Hope this helps

thetestingsite
12-10-2006, 03:52 PM
try the following modified code:



<?php

$blog[] = array(title1,date1,entry1);
$blog[] = array(title2,date2,entry2);
$blog[] = array(title3,date3,entry3);

foreach ($blog as $entry) {

echo "<hr /><h3>".$entry[0]."</h3><br />
<date>".$entry[1]."</date><br />
<div class=\"list\">".$entry[2]."</div>";
}
?>


In your original code, after I put in the semicolons, you recieve a new error.



Parse error: parse error, unexpected '[', expecting ',' or ';' in C:\wamp\www\test\test.php on line 10


I found that your variables entry[2] and entry[3] did not have a dollar sign ($) in front of it.

After fixing that, it did not want to display the first item in the array. So I fixed this by starting the array at 0, so the variables (entry) now look like this

$entry[0] $entry[1] $entry[2]

Always start arrays at 0 unless you have it set otherwise. (ex: first spot in array is empty and you start at 1).

Hope this helps

Twey
12-10-2006, 04:47 PM
Serving XHTML to clients is a bad idea, and this looks like an abuse of the <br> element to me. Use CSS instead.
<?php
$blog = array(
array($title1, $date1, $entry1),
array($title2, $date2, $entry2),
array($title3, $date3, $entry3)
);

foreach ($blog as $entry) { ?>

<hr>
<h3><?php echo($entry[0]); ?></h3>
<date><?php echo($entry[1]); ?></date>
<div class="list"><?php echo($entry[2]); ?></div>

<?php } ?>

boxxertrumps
12-10-2006, 06:03 PM
your script had no errors, but it wont post the data from the array.
this is all i get...

<hr>
<h3></h3>
<date></date>
<div class="list"></div>


<hr>
<h3></h3>
<date></date>

<div class="list"></div>


<hr>
<h3></h3>
<date></date>
<div class="list"></div>

weird....

the testingsite is fine though.

thetestingsite
12-10-2006, 06:11 PM
The reason why Twey's code will not display anything is because in the $blog[] arrays, he has placed dollar signs in front of the items. In mine, it is just plain text (which was posted in the original code). Either of the codes should work fine as long as you assign the variables in Twey's code first.

Let me know if you need any more help.

DimX
12-10-2006, 06:22 PM
In mine, it is just plain text.
Shouldn't the "plain text" be between quotes? Like..

<?php

$blog[] = array('title1','date1','entry1');
$blog[] = array('title2','date2','entry2');
$blog[] = array('title3','date3','entry3');
...

thetestingsite
12-10-2006, 06:26 PM
Oh, yes, you're right. I must have forgot to put it in there, but it did not give me any errors. Odd.

Twey
12-10-2006, 07:01 PM
Those could be defines, variables missing dollar signs, or text missing quotes. I chose to assume variables, since they would have made little sense as text and defines would be inappropriate here.

boxxertrumps
12-10-2006, 08:33 PM
all i need to remember is to escape any quotes i have in my code, but that will only happen for images and links.

but not if i can replace bb code with html.. and i am clueless on how to do that...

i know twey can do this... thetestingsite seems to be smart enough... mwinter and djr33 could help also..

i have a respect for you guys. i appreciate the help you've given me.

after a few minutes of serching and witing code, Ive added the bbcode "person without married perents"ization i call my own...

frst attempt removed

and one test tells me you cant escape square brackets like quotes...

edit

but you can enclose them within quotes, as i can see in a professional bb converter.

<?php

$blog[] = array(title1,date1,"yarisugi.jpgentry1");
$blog[] = array(title2,date2,"entry2");
$blog[] = array(title3,date3,"entry3");

foreach ($blog as $entry) {

//replace bbcode
//Format url text (http://url)

$entry[2] = str_replace("", "<img src=\"", $entry[2]);
$entry[2] = str_replace("", "\" />", $entry[2]);
$entry[2] = str_replace(");
$entry[2] = str_replace(" (", "<a href=\"", $entry[2)", "</a>", $entry[2]);
$entry[2] = str_replace("]", "\">", $entry[2]);

echo "<hr /><h3>".$entry[0]."</h3><br />
<date>".$entry[1]."</date><br />
<div class=\"list\">".$entry[2]."</div>";
}
?>