?
Solved

Replacing Parameters in a URL

Posted on 2008-10-26
2
Medium Priority
?
140 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

765 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