Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 ...

share|improve this question
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. –  Axel Jul 16 '13 at 14:38
 
Please rephrase your question, I don't get what your problem is. –  mvw Jul 16 '13 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? –  andrewsi Jul 16 '13 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 / / –  user2562455 Jul 16 '13 at 14:42
show 1 more comment

3 Answers

up vote 1 down vote accepted
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,);
}
share|improve this answer
 
Thank you so much for your help it really is appreciated a lot sending you good Karma :) –  user2562455 Jul 16 '13 at 14:49
 
You're welcome. –  Pé de Leão Jul 16 '13 at 14:49
add comment

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...

share|improve this answer
 
Thank you very much Brannon I appreciate you taking your time to help out a lot. –  user2562455 Jul 16 '13 at 14:49
 
Glad to help... –  Brannon Jul 16 '13 at 14:55
add comment
$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>";
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.