Solved

Replacing Parameters in a URL

Posted on 2008-10-26
2
136 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
ID: 22809566
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

832 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