ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Char_limit alternative PHP throws error

May 23, 2010 10:34am

Subscribe [4]
  • #1 / May 23, 2010 10:34am

    Lanitha

    13 posts

    I initially posted my question as a reply to this post, but I figured it was unlikely to be seen there any time soon. Hence the new one here.

    As laid out in the post mentioned above, I make use of

    <?php echo substr('{linkurl}', 0, 30) , '...'; ?>

    instead of char_limit.

    I’m using this code snippet in a template of an image gallery (as the char_limit didn’t limit enough). On that page the thumbs of one category are displayed. Works perfectly for all categories except two..?
    When I try to navigate to those categories, they give me these errors:

    Category 1: Parse error: syntax error, unexpected T_STRING in /home/user/website.com/eebase/core/core.functions.php(634) : eval()‘d code on line 14

    Category 2: Parse error: syntax error, unexpected T_STRING in /home/user/website.com/eebase/core/core.functions.php(634) : eval()‘d code on line 16

    Why would this work for the rest of the categories and not for these? Template codes are exactly the same…
    The pertinent part:

    {exp:gallery:entries gallery="mainalbum" orderby="date" sort="desc" dynamic="off" category="{segment_4}" }
       <div class="breadcrumb"> <a href="http://{path=/gallery/index}"><b>Home</b></a> ‹ <a href="http://{path=/gallery/catoverview}"><b>Galleries</b></a> ‹ {category}</div>
        {entries}
        {row}
    <div class="thumbthumbs">
        <a href="http://{image_url}" class="lightbox">http://www.website.com/utilities/phpThumb/phpThumb.php?src={image_url}&w=150&h=150&zc=1&q=100</a> <strong><?php echo substr('{title}', 0, 20) , '...'; ?></strong> </div>
        {/row}
        {/entries}</div>
        {/exp:gallery:entries} 
             </div></div>

    Char_limit does not give me any errors by the way. (Not sure if that helps to narrow it down any.)

    I’m running version 1.6.9, build 20100430

    [Mod Edit: Moved to the How to forum]

  • #2 / May 23, 2010 4:29pm

    Greg Salt

    3988 posts

    Hi Lanitha,

    Firstly, can you please verify that you are in fact using 1.6.9 build 20100430? If you upgraded the site from an earlier version did you copy the system/core files from the download zip to your server?

    Cheers

    Greg

  • #3 / May 23, 2010 5:25pm

    Lanitha

    13 posts

    Hi Greg!
    Yes and yes. I saw the errors first while still on 1.6.8, so first thing I did was update to the latest version and build, all according to the userguide. I did this yesterday.
    This didn’t change anything.
    Although the errors are slightly different… Respectively:

    Parse error: syntax error, unexpected T_STRING in /home/user/website.com/eeroot/core/core.functions.php(653) : eval()'d code on line 15

    and

    Parse error: syntax error, unexpected T_STRING in /home/user/website.com/eeroot/core/core.functions.php(653) : eval()'d code on line 18

    I guess updating did make a difference somehow after all? 😉

  • #4 / May 24, 2010 1:34am

    John Henry Donovan

    12339 posts

    Lanitha,

    Ok so obviously an image title throwing it off in either of those categories. Anything unusual about any of the titles in those categories? Maybe single quotes, odd character etc?

    Can you create a blank template please and only add the following. Please add the category ids of the ones that were throwing the error.Can you then post the link to that template here please?

    {exp:gallery:entries gallery="mainalbum" dynamic="off" category="4|5" }
    <ul>
        {entries}
        {row}
    <li>{title}</li>
        {/row}
        {/entries}
    </ul>
        {/exp:gallery:entries}
  • #5 / May 24, 2010 10:10am

    Lanitha

    13 posts

    Hey John,

    You are right. I thought I’d carefully checked the titles for oddities (‘cause that was one of my first thoughts, too), but I obviously missed the obvious: Those categories have images with titles that have single quotes.
    Is there a way around that? I don’t really want to ask the website owner to omit single quotes in titles…

    The template you asked for can be found here (removed).
    As you can see it does include one title with a single quote, but not two others. One is missing from the same category and one from the other troublesome one. In fact, those aren’t the only entries missing from those two categories… The total entries of those two categories should be 41, and not just the 9 it actually shows on that template..?

  • #6 / May 24, 2010 5:19pm

    Ingmar

    29245 posts

    Those categories have images with titles that have single quotes. Is there a way around that?

    Use double quotes yourself instead of single ones:

    <?php echo substr("{linkurl}", 0, 30) , "..."; ?>
  • #7 / May 25, 2010 1:47pm

    Lanitha

    13 posts

    Thanks for your input, Ingmar.
    That does work.
    However (and I realize my amateurism is hanging out), is it correct to assume that one should now avoid using double quotes in the title?

  • #8 / May 25, 2010 3:01pm

    Ingmar

    29245 posts

    That is correct, unless you escape or pre-process them somehow. It’s just how PHP works, I am afraid.

  • #9 / May 25, 2010 3:41pm

    ender

    1644 posts

    for a reliable solution where various characters in filenames don’t break the page, I’d suggest using PHP’s output buffering functions:

    <?php
        ob_start();
        ?>{linkurl}<?php
        $linkurl = ob_get_contents();
        ob_end_clean();
        echo substr($linkurl, 0, 30) , '...';
    ?>
  • #10 / May 26, 2010 2:51pm

    Lanitha

    13 posts

    Thanks to Ingmar for confirming.
    Thanks to ender for that snippet. I ended up implementing that and it seems to work perfectly!

    Thanks to all other helping hands, as well! 😉

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases