I am currently trying to format url links with parse_url. My goal is to parse the link every time it has the following characters &p (in that order) in it. The if statement is there to check for these characters the in the url before deciding to parse the link or not. For example, if the link has the characters &p (in that order) then it will parse the link and format to my desired choice. I have been able to figure the parsing part but how would I be able to check for these characters &p (in that order)? If you see below example, I only want to remove & from the link.
if($url == '&p' ) // not sure how to check
{
$parsed_url = parse_url($url);
$fragment = $parsed_url['fragment'];
$fragment_parts = explode('/', $fragment);
$formatted_url = array_pop('http://www.website.com?p=$1',$url);
}
else
{
// do something else
}
Example:
Input: http://www.website.com?&p=107
Output: 'http://www.website.com?p=107