Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:37:42+00:00 2026-06-14T19:37:42+00:00

I want to create clean URLs for my database site and I’ve decided that

  • 0

I want to create clean URLs for my database site and I’ve decided that the best way is to create a field in which to store the URLs for their respective entries.

I am using the GenerateUrl function (found here) to create a clean URL from the source name:-

function GenerateUrl ($s) {

    // Convert accented characters, and remove parentheses and apostrophes
    $from = explode (',', "ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u,(,),[,],'");
    $to   = explode (',', 'c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u,,,,,,');

    // Do the replacements, and convert all other non-alphanumeric characters to spaces
    $s = preg_replace ('~[^\w\d]+~', '-', str_replace ($from, $to, trim ($s)));

    // Remove a - at the beginning or end and make lowercase
    return strtolower (preg_replace ('/^-/', '', preg_replace ('/-$/', '', $s)));
}

It works great for the most part, although I am having problems with apostrophes.

Used as quotation marks (i.e. only touching another character on one side) they work fine:-
‘Eiffel Tower (Paris)’ becomes the URL: eiffel-tower-paris

But used as actual apostrophes (i.e. being sandwiched between two characters), not so well:-
St Paul’s Cathedral (London) becomes the URL: st-paul-s-cathedral-london

I’m using PHP 5.4.3 and have code to undo the modifications of magic quotes (should this be the cause of the problem).

Any advice on solving this greatly appreciated.

Thanks,

Andy


Yes, desired URL would be: st-pauls-cathedral-london

I’ve just figured out the original function code I gave DOES work (apostrophes are replaced with nothing at the end of the $from and $to rows respectively).

However, it only seems to works if I apply the function to the name live on the page, i.e.

<?php echo generateurl($attraction['attraction_name']); ?>

But what I am currently doing is applying the function within the index.php file when data is entered into the website. I suspect the problem is coming from the fact that I am applying the function to a value which has already had the below function applied to it (to deal with magic quotes):-

$attraction_name = mysqli_real_escape_string($link, $_POST['attraction_name']);
$attraction_url = generateurl($attraction_name);

I reckon I’ve got to shift some coding around to generate the URL from the attraction_name before it is affected by mysqli_real_escape_string. I’ll let you know how I get on…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:37:43+00:00Added an answer on June 14, 2026 at 7:37 pm

    Yes, it turns out that ‘mysqli_real_escape_string’ was the cause of the problem. A bit of reordering of the code seems to have sorted it:-

    $attraction_url = generateurl($_POST['attraction_name']);
    $attraction_name = mysqli_real_escape_string($link, $_POST['attraction_name']);
    

    Thanks!

    Andy


    How to remove ‘the’, ‘a’, and ‘an’ from start of any URL:-

    Replace the bottom line of the above GenerateUrl function code with:-

    return strtolower (preg_replace ('/^-/', '', preg_replace ('/-$/', '', preg_replace ('/\b(^the|^a|^an)\b/i', '', $s))));
    

    Useful advice on this subject from Stack Overflow.

    And good article on using \b for word boundaries in regular expressions from Regex Tutorial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create wordpress website into which I want create user management... That means
I want to create a new field (or two) in my table that is
I want to create some tables in database so for that i wright some
I want to create a winform that connect to a database to do things.
i want create a custom json data from the mssql 2008 results so that
I want create module which update list of usb devices automatically (not only mass
I'm trying to create clean URLs on my website. Now I succeeded in configuring
I want to create a web site with pure PHP. I want to hide
I have a method that tries to create a Uri and then clean it
I'm trying to create a clean jquery pop-up with different functionalities. I dont want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.