Solved

Replacing Parameters in a URL

Posted on 2008-10-26
2
134 Views
Last Modified: 2010-04-06
I have users entering a URL, and I need to make sure it is in the following format:
http://api.somewhere.com/etc/....

people seem to be entering in formats like this:
http://www.somewhere.com/etc/....
http://www.wrongname.com/etc/....

The 'etc/....' part changes from page to page

So I am looking for someway to make sure the URL is always in the correct format....

Thanks!
0
Comment
Question by:interclubs
2 Comments
 
LVL 12

Accepted Solution

by:
hfraser earned 500 total points
Comment Utility
Here's a snippet of code that shows how to use preg_replace to do this.


<?php
echo preg_replace("/http:\/\/\w+\.\w+\.\w+\/(.*)/", "http://api.somewhere.com/$1", "http://www.somewhere.com/stuff/index.html");
?>
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now