[wplug] Re: PHP script question

Kevin Squire gentgeen at wikiak.org
Fri Feb 1 12:06:05 EST 2008


Sorry guys and gals ... I should have searched for just 5 mins longer. I
re-adjusted my search terms after sending out the email, and found my own
solution:

Just added:
   $title = substr($title, 0, strpos($title, "|"));

Just outside the first "if" loop.  For the sake of the future searchers:

function getTitle($file){
    global $htmltypes;
    $title="";
    $p=pathinfo($file);
    if(!in_array(strtolower($p['extension']),$htmltypes)){
        $f=file_get_contents($file);
        if(preg_match("'<title>(.+)</title>'i", $f, $matches)){
            $title=$matches[1];
        }
    }
    $title = substr($title, 0, strpos($title, "|"));
    $title=$title?$title:basename($file);
    return htmlentities(trim(strip_tags($title)));
}

On 2/1/08, Kevin Squire <gentgeen at wikiak.org> wrote:
>
> First - Thank you, those of you that replied to my last PHP question - I
> have not researched what you mentioned yet, but will and will reply back on
> that thread later.
>
> I am thinking of using the Dynamic Site Map Generator found here -
> http://apptools.com/phptools/dynamicsitemap.php  I searched the site for
> some form of "contact me" as well as searched the source code, but had no
> luck - so I was hoping you all could help me out again.
>
> There is a function that searches the webpages for the TITLE tag, then
> reports back using the contents of that tag.  The one problem I have is that
> all our pages have a title format of:
>        PAGE TITLE | COMPANY NAME
>
> So my sitemap then gets filled with " | COMPANY NAME" after every single
> page title - very cluttered and difficult to browse.  It could work, but I
> would really like to clean it up some.  I would like to add to the PHP
> function the equivalent of the command:
>      cut -f1 -d"|"
> But I have no idea how to do so.
>
> Here is the function
>
> function getTitle($file){
>     global $htmltypes;
>     $title="";
>     $p=pathinfo($file);
>     if(!in_array(strtolower($p['extension']),$htmltypes)){
>         $f=file_get_contents($file);
>         if(preg_match("'<title>(.+)</title>'i", $f, $matches)){
>             $title=$matches[1];
>         }
>     }
>     $title=$title?$title:basename($file);
>     return htmlentities(trim(strip_tags($title)));
> }
>
>
> --
> http://gentgeen.homelinux.org
>
> #############################################################
> Associate yourself with men of good quality if you esteem
> your own reputation; for 'tis better to be alone then in bad
> company.        - George Washington, Rules of Civility




-- 
http://gentgeen.homelinux.org

#############################################################
Associate yourself with men of good quality if you esteem
your own reputation; for 'tis better to be alone then in bad
company.        - George Washington, Rules of Civility
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.wplug.org/pipermail/wplug/attachments/20080201/49fd5327/attachment.html


More information about the wplug mailing list