Kategorier

Vise en RSS-feed

Dette eksemplet viser hvordan du bruker den nedlastbare bibliotekene fra boka Webbots, edderkopper, og Skjermen skrapere å vise en RSS feed.

5 linjer med kode og 3 er de inkluderte filene

<? Php
REQUIRE_ONCE 'LIB_rss.php';
REQUIRE_ONCE 'LIB_http.php';
REQUIRE_ONCE 'LIB_parse.php';
$ Rssfeed = download_parse_rss (" http://newsrss.bbc.co.uk/rss/sportonline_world_edition/football/rss.xml ");
display_rss_array ($ rssfeed)
?>

Lag en katalog

<? Php
mkdir ("/ htdocs / testdir", 0644);
echo "Test katalog gjort med hell";
?>

Sjekk en url eksisterer


function url_exists($url)
{
$ch = curl_init($url);

curl_setopt ($ ch, CURLOPT_HEADER, true);
curl_setopt ($ ch, CURLOPT_POST, false);
curl_setopt ($ ch, CURLOPT_FAILONERROR, true);
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true);
curl_exec ($ ch);
$ CurlInfo = curl_getinfo ($ ch, CURLINFO_HTTP_CODE);

curl_close ($ ch);

if ($ curlInfo! = 200 & & $ curlInfo! = 302 & & $ curlInfo! 304 =)
(
return false;
)
annet
(
return true;
)
)

få sesongen med php

/ / Få aktuell måned
$ CurrentMonth = date ("m");

/ / Regne ut sesongen
if ($ currentMonth> = "03" & & $ currentMonth <= "05")
$ Sesongen = "våren";
elseif ($ currentMonth> = "06" & & $ currentMonth <= "08")
$ Sesongen = "sommer";
elseif ($ currentMonth> = "09" & & $ currentMonth <= "11")
$ Sesongen = "høst";
annet
$ Sesongen = "vinter";

Is.gd korte url

dette eksemplet viser hvordan du får et kort url bruker tjenesten fra is.gd

<? Php
/ *
Få en is.gd kort url med PHP
* /
funksjon isgd ($ url)
(
$ Lm = curl_init ();
$ Timeout = 5;
curl_setopt ($ ch, CURLOPT_URL, ' http://is.gd/api.php?longurl = ' . $ url);
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout);
$ Content = curl_exec ($ ch);
curl_close ($ ch);
/ / Returnere data
returnere $ innhold;
)

/ / Hvordan du bruker
$ Shorty = isgd (' http://progged.net ');
echo $ Shorty;
?>

IPhone deteksjon

if (stristr ($ _SERVER ['HTTP_USER_AGENT'], 'iPhone'))
(
/ / Viderekobler til en iPhone-versjon
)