Solved

Replacing Parameters in a URL

Posted on 2008-10-26
2
139 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

707 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