SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Title trimming

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Title trimming

    I run a Digg style website that allows people to submit blog posts etc...

    I have been trimming the URL titles automatically using:

    PHP Code:
    if( preg_match'~<title>(.*?)([^:\-]*?)</title>~is'str_replace'&raquo;'':'$this->html ), $matches ) )
    {
      
    $this->url_title $matches[2];

    this took a page title formatted like:

    Code:
    Website name - Post title
    and made it:

    Code:
    Post title
    Now I am trying to reverse it so that it will make it the opposite and only take the "Website name" like in the example above.

    But for the life of me, I cannot get it to work.

    What is the proper way of doing this?

    Thanks.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if(preg_match'~<title>([^:\-]*?)(*?)</title>~is'str_replace'&raquo;'':'$this->html ), $matches)){
      
    $this->url_title $matches[1];

    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the quick reply, however, it resulted in a blank title.


    Geoserv

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ah, ok, how about:
    Code:
    '~<title>([^:\-]*?)[:\-](*?)</title>~is'
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    ~<title>([^:\-]*?)[:\-](.*?)</title>~is
    my mobile portal
    ghiris.ro

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oops, missed the wildcard!

    Not my day today, apparently!
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect, thanks for help guys.

    This was really driving me crazy.


    Geoserv.


Tags for this Thread

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
  •