Solved

Replacing Parameters in a URL

Posted on 2008-10-26
2
138 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

738 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