SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grap Html title and turn it into Meta title

    Hi, is this possible? I want to grab the product title on my product pages and then turn it into a meta title. For example this page http://shockingtshirts.com/?i=3583109393 has the title "Does Not Compute", could I some how get that and then turn it into the meta title before the page is output to html?

    This is quite a tricky and complex CGi backend which is why I can't get the meta title.
    Domain Name Coupon Codes for popular registers
    Web Hosting Coupon Codes save on website hosting

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well, http://shockingtshirts.com/?i=2244574196 doesn't even list the 'Relax' title...

    Hmm...

    PHP Code:
    <?php

    function get_product_name($id){
      
    preg_match(
        
    '~(?<=<!--\s)(.+)(?=\s-->)~',
        (string)
    file_get_contents(
          
    'http://shockingtshirts.com/?i=' $id
        
    ),
        
    $match
      
    );
      return isset(
    $match[0]) ? $match[0] : '' ;
    }

    $product_name get_product_name('3583109393');

    ?>
    Edit: Oh, actually it does. This would be a much better match that the HTML comment I found in your source.
    Code:
    <span class="cpshopbreadcrumbtext">Relax</span>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    uhhhh the code is already there for you to grab the name

    <title><?= $product_name; ?></title>
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shaydez View Post
    uhhhh the code is already there for you to grab the name

    <title><?= $product_name; ?></title>
    I don't think it is.
    Code:
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>	Buy crazy t-shirts online</title>
    <meta name="author" content="Shocking T-Shirts" />
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    Well, http://shockingtshirts.com/?i=2244574196 doesn't even list the 'Relax' title...

    Hmm...

    PHP Code:
    <?php

    function get_product_name($id){
      
    preg_match(
        
    '~(?<=<!--\s)(.+)(?=\s-->)~',
        (string)
    file_get_contents(
          
    'http://shockingtshirts.com/?i=' $id
        
    ),
        
    $match
      
    );
      return isset(
    $match[0]) ? $match[0] : '' ;
    }

    $product_name get_product_name('3583109393');

    ?>
    Edit: Oh, actually it does. This would be a much better match that the HTML comment I found in your source.
    Code:
    <span class="cpshopbreadcrumbtext">Relax</span>
    The above code doesn't work, not sure how it would anyway, can you explain please how I would use it? The relax t-shirt has this ID 2244574196 and that ID is for another tshirt, the one I posted first.

    Quote Originally Posted by Shaydez View Post
    uhhhh the code is already there for you to grab the name

    <title><?= $product_name; ?></title>
    that's not how it is, wish it was that easy
    Domain Name Coupon Codes for popular registers
    Web Hosting Coupon Codes save on website hosting

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Coupon Codes View Post
    ... can you explain please how I would use it?
    How would you like to use it? You're going to have to provide more information than what you have already.

    Looking at the html output, it appears you're using WordPress, does it support the dynamic naming of the page title via its API?

    You say "it doesn't work", yet haven't explained how you would like it to work.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Zealot
    Join Date
    Oct 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    How would you like to use it? You're going to have to provide more information than what you have already.

    Looking at the html output, it appears you're using WordPress, does it support the dynamic naming of the page title via its API?

    You say "it doesn't work", yet haven't explained how you would like it to work.
    Sorry for not explaing more. It really is quite complicated. It is wordpress but I have implemented a shopping cart for Cafepress called CPshop into wordpress. But I hit a brick wall so I thought maybe there is an easy way to grab the product name with php and output as the meta title.

    This thread here has all the details: http://www.marty.net/cgi/marty/board...num=1281538796
    Domain Name Coupon Codes for popular registers
    Web Hosting Coupon Codes save on website hosting


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
  •