[wplug] Re: PHP Script Question from Kevin Squire

Chad Mikolajcik chadmiko at gmail.com
Fri Feb 1 13:02:40 EST 2008


------------------------------
>
>
> Message: 6
> Date: Fri, 1 Feb 2008 11:46:42 -0500
> From: "Kevin Squire" <gentgeen at wikiak.org>
> Subject: [wplug] PHP script question
> To: wplug at wplug.org
> Message-ID:
>        <386ebf050802010846u78385d82o224fb4756c4e09ab at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> 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



I think it will so long as there's only one '|'  in $title, this will work.
Then you should find the title you want in $extracted_title


    if( !is_null( $title )){
         $co_name = trim( substr(strrchr($title, "|"), 1));
         $extracted_title = trim( substr($title, 0, strripos($title, "|")));
         echo "<br>Page title:  " . $extracted_title . "\t\tCompany Name: "
. $co_name;
    }


--Chad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.wplug.org/pipermail/wplug/attachments/20080201/661fd108/attachment.html


More information about the wplug mailing list