[ Q_Line @ 12.07.2006. 10:27 ] @
Pozdrav,

Kako npr. da u .php stranici koja sadrzava razlicite php ili html tagove npr. iz dijela "href"-a:

Code:
http://www.elitesecurity.org/poruka/novatema/12?refresh=MTE1MjY5NTk4OQ==


izvucem samo elitesecurity.org i da se to preko
Code:
print i/ili echo "";
ispise u stranici!? :)

Tnx
[ NikolaVeber @ 12.07.2006. 10:43 ] @
http://weblogtoolscollection.com/regex/regex.php
[ Q_Line @ 12.07.2006. 10:49 ] @
Code:
// get last two segments of host name
preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
echo "domain name is: {$matches[0]}\n";
?>

This example will produce:

domain name is: php.net


Tnx na brzom odgovoru :)
[ Nemanja Avramović @ 12.07.2006. 10:58 ] @
Za www.nekidomacisajt.co.yu će ti taj kod vratiti "co.yu" (ja mislim... probaj)
[ 1r0nM4n @ 12.07.2006. 11:04 ] @
Možda može da ti koristi i funkcija parse_url()
Code:
<?php
    $url = parse_url("http://www.elitesecurity.org/p...ma/12?refresh=MTE1MjY5NTk4OQ==");
    echo $url[host];
?>

Ovo će da ispiše www.elitesecurity.org
Detaljnije... http://www.php.net/manual/en/function.parse-url.php

p0z
[ 1r0nM4n @ 12.07.2006. 11:08 ] @
JaHvram je u pravu...
Code:
$host = "www.sajt.co.yu";
preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
echo "domain name is: {$matches[0]}\n";

Rezultat:
Citat:
domain name is: co.yu

p0z
[ sale83 @ 12.07.2006. 13:45 ] @
Citat:
1r0nM4n: JaHvram je u pravu...
Code:
$host = "www.sajt.co.yu";
preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
echo "domain name is: {$matches[0]}\n";

Rezultat:
p0z



Zato ovako nekako treba da izgleda( trebalo bi da radi):

Code:

preg_match('/[^.]+\.[^.]+\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}<br>";



Poz
sale
[ Br@nkoR @ 12.07.2006. 14:51 ] @
Code:
$links = Array('http://www.elitesecurity.org/p...ma/12?refresh=MTE1MjY5NTk4OQ==',
               'http://www.elitesecurity.org',
               'http://elitesecurity.org/',
               'www.elitesecurity.org',
               'elitesecurity.org',
               'http://www.elitesecurity.co.yu/test/',
               'http://elitesecurity.co.yu/test/'
               );

for($i = 0, $len = count($links); $i < $len; $i++) {
  preg_match("/^(http:\/\/)?(www.)?([^\/]+)/i", $links[$i], $matche);
  echo ($i+1) . '. ' . $matche[3] . '<br />';
}
[ sale83 @ 12.07.2006. 15:49 ] @
Br@nkoR
Taj tvoj kod je dobar samo ako je link tipa https onda ti nece raditi .


Poz
sale

[ Br@nkoR @ 12.07.2006. 16:56 ] @
očekivao sam da će to neko napiše
Code:

$links = Array('http://www.elitesecurity.org/p...ma/12?refresh=MTE1MjY5NTk4OQ==',
               'https://www.elitesecurity.org',
               'http://elitesecurity.org/',
               'www.elitesecurity.org',
               'elitesecurity.org',
               'http://www.elitesecurity.co.yu/test/',
               'https://elitesecurity.co.yu/test/'
               );

for($i = 0, $len = count($links); $i < $len; $i++) {
  preg_match("/^(https?:\/\/|www\.)*([^\/]+)/i", $links[$i], $matche);
  echo ($i+1) . '. ' . $matche[2] . '<br />';
}


da li treba i za ftp, nntp, news, file, mailto ...


Edit: zaboravio sam da backslash-ujem tačku

[Ovu poruku je menjao Br@nkoR dana 12.07.2006. u 18:21 GMT+1]
[ Q_Line @ 17.07.2006. 12:56 ] @
Hmmm, sad mi se pojavio drugi problem, doduse ovaj je ok rijesen, medjutim kako OVO isto uraditi za smarty php, tj npr. za varijablu:

Code:
{$link.URL|escape}

i za nju izdvojiti "domenu"!?

Tnx
[ Br@nkoR @ 17.07.2006. 14:15 ] @
Možeš napraviti nov modifikator, npr za kod koji sam ja postavio:
Code:
function smarty_modifier_cuturl($string) {
  preg_match("/^(https?:\/\/|www\.)*([^\/]+)/i", $string, $matche);
  return $matche[2];
}


i posle ideš:
Code:
{$link.URL|escape|cuturl}
[ Nemanja Avramović @ 17.07.2006. 14:35 ] @
A gde treba ubaciti (definisati) funkciju smarty_modifier_cuturl? Bilo gde ili treba "proširiti" klasu Smarty? Sorry, verovatno odgovor postoji u Smarty manual-u ali nisam radio sa Smarty-jem skorije :|
[ Br@nkoR @ 17.07.2006. 16:25 ] @
Npr. u folder plugins kreiraš fajl modifier.cuturl.php, i u njega staviš ovu funkciju.
A možeš imati i poseban folder u koji ćeš smeštati svoje modifikatore, funkcije (plugins)... ($plugins_dir)
[ Nemanja Avramović @ 17.07.2006. 16:59 ] @
Hvala
[ Br@nkoR @ 17.07.2006. 17:08 ] @
Nema na čemu
Ovo sa zaboravio, da možeš i pomoću register_modifier:
Code:

function cuturl($string) {
  preg_match("/^(https?:\/\/|www\.)*([^\/]+)/i", $string, $matches);
  return $matches[2];
}

$smarty = new Smarty;
$smarty->register_modifier("cuturl", "cuturl"); 
$smarty->display('index.tpl');
[ Q_Line @ 18.07.2006. 09:06 ] @
Moja iskrena ZAHVALA! :)

ZAKON STE ;)