Design Quote Quick Script
by Dave Johnson
February
4
2011
This is some code I wrote up real quick for the footer of my website. I was using the “Straight Up” javascript from QuotesOnDesign.com however this included some very long quotes that are not really quotes at all more like essays. So I used the API instead and wrote some php that has a word limit and if it goes over then it posts a link that the user can fallow to finish reading the quote.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php $jsonurl = "http://quotesondesign.com/api/3.0/api-3.0.json"; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json); $id = $json_output->id; $quote = $json_output->quote; $author = $json_output->author; $permalink = $json_output->permalink; $position=300; if (strlen($quote) > $position){ $post = substr($quote,$position,1); if($post !=" "){ while($post !=" "){ $i=1; $position=$position+$i; $post = substr($quote,$position,1); } } $post = substr($quote,0,$position); $post .= "...<a href=\"" . $permalink . "\">(More)</a>"; } else{ $post = $quote; }?> <blockquote id="qod-quote"> <?php echo $post; ?> <a href="<?php echo $permalink ?>"> — <?php echo $author ?> </a> </blockquote> |