Results 1 to 10 of 10

Thread: t string error?

  1. #1
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default t string error?

    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?
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    try the following modified code:

    PHP 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
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Serving XHTML to clients is a bad idea, and this looks like an abuse of the <br> element to me. Use CSS instead.
    Code:
    <?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 } ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    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.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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.
    Last edited by thetestingsite; 12-10-2006 at 06:20 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    In mine, it is just plain text.
    Shouldn't the "plain text" be between quotes? Like..
    PHP Code:
    <?php

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

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Oh, yes, you're right. I must have forgot to put it in there, but it did not give me any errors. Odd.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    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,"[img]yarisugi.jpg[/img]entry1");
    $blog[] = array(title2,date2,"entry2");
    $blog[] = array(title3,date3,"entry3");

    foreach ($blog as $entry) {

    //replace bbcode
    //Format [img]url[/img] text

    $entry[2] = str_replace("[img]", "<img src=\"", $entry[2]);
    $entry[2] = str_replace("[/img]", "\" />", $entry[2]);
    $entry[2] = str_replace("[url=", "<a href=\"", $entry[2]);
    $entry[2] = str_replace("[/url]", "</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>";
    }
    ?>
    Last edited by boxxertrumps; 12-10-2006 at 10:06 PM. Reason: update
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •