takze vytvoril som si jednoduchy guesbook bez pouzitia mysql, su tam inputy na meno a spravu. Okrem toho sa v sprave pise este datum, ip adresa a prehliadac s OS (na to som pouzil http user agenta)
nastavil som si ze napriklad slovo opera sa mi zameni s obrazkom opera.png... windows za win.png atd, nejak takto:
$agent = $HTTP_USER_AGENT;
$agent = str_replace("Opera","<IMG SRC=\"smile/opera.png\" alt=\"\">", $agent);
ale problem je ze sa to sice nahradi ale potom tam mam zvysny text z toho http user agentu, dal by sa nejako odstranit?
prikladam screen:
Fórum › PHP
Problem s guestbookom

A čo toto?
$agent = $HTTP_USER_AGENT;
if (substr_count(strtolower($agent), "opera") > 0) { $vypis = '<IMG SRC="smile/opera.png" alt="">'; }
if (substr_count(strtolower($agent), "windows") > 0) { $vypis .= '<IMG SRC="smile/win.png" alt="">'; }
Prosto presne to, čo napísal Tomas, akurát si nebudeš prepisovať premennú $agent, ale budeš mať nejakú ďalšiu, napr. $vypis, do ktorej budeš všetko pripájať cez .=
zdravim,
vyzkousej jeste tohle:
$prohlizece = array(
"opera" => "opera.png",
"firefox" => "ff.png",
"ie" => "ie.png",
);
$os = array(
"widnows" => "win.png",
"linux" => "linux.png",
);
$agent = $HTTP_USER_AGENT;
$obrazky = "";
foreach($prohlizece as $pro => $obr){
if(strpos($agent, $pro) !== false) $obrazky .= '<img src="smiles/'.$obr.'" alt="">';
}
foreach($os as $pro => $obr){
if(strpos($agent, $pro) !== false) $obrazky .= '<img src="smiles/'.$obr.'" alt="">';
}
vysvetleni kodu: promenna $prohlizece obsahuje pole, kde jeho indexy je text, kterym $HTTP_USER_AGENT urcuje prohlizec(prepis na hodnoty, ktere vraci, ja je neznam, tak sem tam hodil "ilustracni") a hodnota pod danym indexem je obrazek s danym prohlizecem. Stejne je udelano pole $os, kde sou prozmenu operacni systemy, plati to stejne, co u prohlizecu
foreach() je cyklus pro prujezd polem, v promenne $pro je index pole a v promenne $obr je obsah pole
strpos zjistuje, zda dany text je obsazen v jinem textu, pokud tam je, prida se do promenne $obrazky obrazek prohlizece/os, pak uz jen staci vypsat promennou $obrazky
Jestli chces obrazky nejak oddelit, pridej do $obrazky mezi cykly dany oddelovac
snad sem to napsal tak, ze se to da pochopit
<?php
$user = $_SERVER['HTTP_USER_AGENT'];
$os = array("windows", "Linux");
function os_img( $user, $os ) {
foreach ($os as $substring) {
if (substr_count(strtolower($user), $substring) > 0) {$vypis = '<IMG SRC="smile/'.$substring.'.png" alt="">'; }
}
return $vypis;
}
?>
máš pro OS, stačí uprovit i pro prohlížeč
EDIT: POZDĚ
tak som to cele skopiroval a zmenil som hodnoty na take ake maju byt ale aj tak mi to nechce nic nahradit...
prikladam ten script v txt
http://fet.cholerik.cz/ukazka.txt

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 12 hostů
Moderátoři diskuze