Results 1 to 4 of 4

Thread: Shortening a URL with preg_replace

  1. #1
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Shortening a URL with preg_replace

    What would be the easiest way to shorten a URL with preg_replace? Let's say a URL looks like this:

    http:/ /someurl.com/file_1/something_else/new/file_2.html

    I want to reduce it to let's say 30 characters:

    http:/ /someurl.com/file_1/some...

    Thanks!

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I think there's a little more to it if you still want the link to work

    Have a look at this: https://github.com/briancray/PHP-URL-Shortener
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by Beverleyh View Post
    I think there's a little more to it if you still want the link to work

    Have a look at this: https://github.com/briancray/PHP-URL-Shortener

    Actually, no, I don't want it to work. I just want it for a preview and it doesn't matter if it works or not.

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    In that case, why not use substr() http://ca3.php.net/manual/en/function.substr.php
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

Similar Threads

  1. Help with preg_replace
    By qwikad.com in forum PHP
    Replies: 7
    Last Post: 09-02-2014, 05:11 PM
  2. Shortening a huge list using an array value
    By jason_kelly in forum JavaScript
    Replies: 1
    Last Post: 05-09-2013, 10:07 PM
  3. Resolved preg_replace
    By ggalan in forum PHP
    Replies: 2
    Last Post: 02-25-2012, 05:10 AM
  4. shortening RSS Feed in Advanced RSS Ticker
    By cbcostanza in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 10-23-2007, 07:28 PM
  5. Shortening HTML with Javascript
    By Agent Moose in forum JavaScript
    Replies: 15
    Last Post: 02-28-2007, 09:37 PM

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
  •