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 4093258
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:35:44+00:00 2026-05-20T19:35:44+00:00

I have this link: http://mysite/myfolder/it/my-keywords.html and want to replace /it/ with /es/ (2 letter

  • 0

I have this link:
http://mysite/myfolder/it/my-keywords.html and want to replace /it/ with /es/ (2 letter country codes)

I could explode() with “/” delimiter but would like to understand if preg_replace would be better.

tried:

preg_replace("/\/([a-z]{2})/\/", $link, $country);

EDIT
answer:

preg_replace("/\/[a-z]{2}\//", "/$country/", $link);
  • 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-05-20T19:35:44+00:00Added an answer on May 20, 2026 at 7:35 pm

    preg_replace is like a swiss army knife. preg rather than ereg means it uses perl compatible regular expressions. It matches first param (regex), replaces with second param (string) in third param (string).

    Regular expressions are optimized for efficiency by using search tree cutoff techniques etc… so are generally efficient alternative method.

    This should do what you want.

    preg_replace("/\/it\//","/es/","http://mysite/myfolder/it/my-keywords.html") 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a jquery slider, link: http://ekallevig.com/jshowoff/ this is my html code: <div id=features>
Let's say I have a links like this: http://mysite.com?i=343435&f=224&u=334 and this link is constant
I have this link: http://mysite.com/subdirectory/something/stuff/index.php What regex would I be able to use that
I want to configure Kohana 2.x to have links in this format: http://localhost/mysite/web/admin/support instead
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that
I have this link which i need to translate in a php variable. http://www.facebook.com/dialog/apprequests?app_id=346824075388300&to=1149862205&message=Facebook+Dialogs+are+so+easy%21&redirect_uri=http%3A%2F%2Fpenelope-ns.net%2Ffb%2F
I have installed Qt for windows CE using this link http://qt.nokia.com/products/platform/qt-for-windows-ce for visual studio8,
am using the application in this link http://www.jeasyui.com/tutorial/app/crud2.php .I have added one more column
i have a DTD file which i used to accessed through this link: http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd
I have tried to do this refering to following link. http://skypher.com/index.php/2008/07/28/function-list-for-php/ But no success.

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.