Jump to content

Recommended Posts

HI,

 

I want to create urls dynamically when i am inserting the new data to database.

 

ForExample,

 

If the story title is :

 

What is new in Site?

 

It should be converted as :

 

what-is-new-in-site.html

 

It shouldn't allow any special characters in the URL.

 

How can I do this?

I'd make one small change to that:

<?php
  $str="What is new in Site?";
  $new_str=strtolower(str_replace(" ","-",$str));
  echo $str;
  echo $new_str;
?>

 

Best to keep URLs lower case. You'd also want to remove all non allowed characters like the ? as that wouldn't be allowed in the URL. Not exactly sure how that'd be done although I have written this regex string to grab everything except the ?

 

([ a-zA-Z]*)

I dont quite understand.

 

Do you want an error if anything but alpha-numeric and - come up

 

OR

Do you want it just to remove them so

 

HE-LLO$^ M"Y n@A~me IS C-h(oc*o&pi

 

would become

 

HE-LLO MY nAme IS C-hocopi

 

~ Chocopi

 

Do you want it just to remove them so

 

HE-LLO$^ M"Y n@A~me IS C-h(oc*o&pi

 

would become

 

HE-LLO MY nAme IS C-hocopi

 

Yes, I want to remove all..but the spaces will be replaed with "-" and also there should not more than one "-" continuosly like "---". It should be trimed to "-"

 

 

Thanks,

krishna

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.