E
E
eddasphp2015-09-22 22:49:57
PHP
eddasphp, 2015-09-22 22:49:57

And how to split into 5 paragraphs Php?

$get = file_get_contents("http://api.test.net/json.aspx?AppId={myid}&Query=test&Sources=Web&Market=en-US&WebFileType=%27HTML%27&web.offset=1&Web.Count=20");
$decode = json_decode($get, TRUE); // TRUE for in array format
foreach($decode['SearchResponse']['Web']['Results'] as $res) {
$str  = $res['Description'];
for($i = 1; $i <= 20; $i++) {
        echo $str.$i.' ';
        if ($i==7 || $i==3 || $i==2 || $i==4 || $i==4){
                echo '</p><p>';
        }
}

1 paragraph - here 7 first results
2 paragraph - here 3 next results
3 paragraph - here 2 next results
4 paragraph - here 4 next results
5 paragraph - here 4 next results

Some bullshit is coming out. What am I doing anyway?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2015-09-22
Protko @Fesor

how to split text into 5 parts php?
in general, you need to cut the array with the results (array_slice) and only then deal with the generation of html. First we process the data and then only render it, it will be much easier this way.

A
Alexey, 2015-09-23
@dzheka3d

You did not open the paragraph before the loop and did not close it after it.
It turns out that it will work correctly for you at least from the second line

Z
Zerzess, 2015-09-23
@Zerzess

echo '<p>';
for($i = 1; $i <= 20; $i++) {
        echo $str.$i.' ';
        if ($i==7 || $i==3 || $i==2 || $i==4 || $i==4){
                echo '</p><p>';
        }
echo '</p>';

And there will be 4 paragraphs and not 5. digits 4 in check 2 times

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question