0

Hi all I am sorry if this is a dumb question and I understand I might get banned for asking it but after a lot of work reading over PHP manual, reading the relevant chapters in PHP5.3 and scowering across Stackoverflow I am stuck in my tracks.

I have been universally format the url's taken in from a Search API I have tried to use parse_url(), trim and others unsuccessfully I decided upon str_replace

foreach ($jsonObj->RESULT as $value) {

 $BLekko_results[] = array(
                            'url' => strip_tags($value->url),
            'url' => str_replace("http://www.", "http://", $value->url),
                    'url' => str_replace("https://www.", "http://", $value->url),
                     'url' => str_replace( " http://", "http://", $value->url),
                     'url' => str_replace( " http://", "http://", $value->url),
                      title' => $value->url_title,); }

I plead humbly for you help ...

6
  • 2
    What is your question? You aren't clear what you are trying to achieve. Post a URL you have, and the results you are expecting. Commented Jul 16, 2013 at 14:38
  • Please rephrase your question, I don't get what your problem is. Commented Jul 16, 2013 at 14:39
  • telegraph.co.uk/technology/amazon Commented Jul 16, 2013 at 14:39
  • @user2562455 - what are you trying to achieve? And does it matter that there's a single quote missing from title on the last line? Commented Jul 16, 2013 at 14:41
  • Ok, I am trying to get uniformed url address starting with (http;//") I am doing this because part of my program compares the urls in string format to each other. I thought that the above would be able to check what type of prefix each url address had and change it to the desired (http;//") ---but it gives out h t t p s / / www. and h t t p / / www. when the desired result it h t t p / / Commented Jul 16, 2013 at 14:42

3 Answers 3

1
foreach ($jsonObj->RESULT as $value) {
    $url = trim($value->url);
    $find = array("http://www.", "https://www.", "https://");
    $BLekko_results[] = array(
        'url' => str_replace($find, "http://", $url),
        'title' => $value->url_title,);
}
1
  • Thank you so much for your help it really is appreciated a lot sending you good Karma :) Commented Jul 16, 2013 at 14:49
1

Perhaps try something like this:

public function processURLString($urlString) {
    $urlString = trim($urlString);

    if($urlString) {
        $urlString = preg_replace('/https?:\/\//', '', $urlString);
        $urlString = trim($urlString);
        $urlString  = 'http://'.$urlString;
    }

    return $urlString;
}

And then you can add or remove www etc...

1
  • Thank you very much Brannon I appreciate you taking your time to help out a lot. Commented Jul 16, 2013 at 14:49
0
$BLekko_results = array();
foreach ($jsonObj->RESULT as $value) {
    $value = strip_tags($value->url);
    $updatedURL = str_replace(array('http://www.','https://www.','https://'),"http://",$value->url);
    $updatedTitle = $value->url_title;
    $BLekko_results[] = array('url'=>$updatedURL,'title'=>$updatedTitle);
}
echo "<pre>";
print_r($BLekko_results);
echo "</pre>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.