0

We have a client who wants to output cinema listings on their website. This particular cinema has provided us with a link to retrieve the information from. This link is simply outputted in plain text, with the elements seperated by ~|~

I have set up a curl script to grab this plain text from the url and display it as plain text on the clients website. However I now need a way of pulling this information into div classes so I can style it with CSS. Also there are a few links which I need to format into buttons that link to book the show.

This is my current code:

<?php

function curl_get_file_contents($URL)
    {
        $c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $URL);
        $uf_contents = curl_exec($c);
        curl_close($c);

        $contents = str_replace("~|~"," ",$uf_contents);

        if ($contents) return $contents;
            else return FALSE;
    }

echo "<ul>";
echo curl_get_file_contents("THE URL");
echo "</ul>"

?>

All this is doing currently is replacing the separators with a space. I'm really confused on this one and I'm not 100% proficient with PHP. Any ideas?

Thanks in advance

2
  • 2
    What is wrong with looping through the contents you got from curl and adding the tags? Commented Jul 22, 2013 at 10:46
  • ~|~ is a weird separator :\ Commented Jul 22, 2013 at 11:02

2 Answers 2

4

Try this

foreach (explode("~|~", file_get_contents("URL")) as $item)
{
    echo '<div>' . $item . '</div>';
}
Sign up to request clarification or add additional context in comments.

Comments

0

As you said in your description, your function is just replacing the character with a space.

What you need is split the file and separate in different arrays depending from the format.

to make an array you use the function explode

    //this will split the content in an array
    $theArray = explode("~|~"," ",$uf_contents);

    //here you can assign a different class depending from the value (this just if you
    can distinguish between the various variable quite easily.. For example
    a website because of the .com a rating because of the number). Below there are
    example of website, rating.

    foreach($theArray as $item){
        if(strpos($item,'.com') === true){
            echo "<div class='webSite'>" . $item . "</div>";
        }elseif($item >=0 && $item <= 100){
            echo "<div class='webSite'>" . $item . "</div>";
        }else{
            echo "<div class='normalDiv'>" . $item . "</div>";
        }}

I have given you an example, but I dont know what the file includes and I cant give you a good validation method... If it is a nice table, than you can format it quite esily using the index number..

Comments

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.