Zastąp adresy URL w tekście linkami HTML
Oto jednak projekt: na przykład umieszczam link taki jak
W textarea. Jak sprawić, aby PHP wykryło, że jest to link http://
, a następnie wydrukowało go jako
print "<a href='http://www.example.com'>http://www.example.com</a>";
pamiętam, że robiłem coś takiego wcześniej, jednak nie był to głupi dowód, że łamał się dla złożonych linków.
Innym dobrym pomysłem byłoby, gdybyś miał link taki jak
Http://example.com/test.php?val1=bla&val2blablabla%20bla%20bla.bl
Fix it so it does
print "<a href='http://example.com/test.php?val1=bla&val2=bla%20bla%20bla.bla'>";
print "http://example.com/test.php";
print "</a>";
[3]}ten jest tylko po myśli.. stackoverflow też pewnie by się przydał :d
Wszelkie Pomysły
15 answers
Przyjrzyjmy się wymaganiom. Masz jakiś zwykły tekst dostarczony przez użytkownika, który chcesz wyświetlić z hiperłączami Url.
- prefiks protokołu "http://" powinien być opcjonalny.
- należy akceptować zarówno domeny, jak i adresy IP.
- każda ważna domena najwyższego poziomu powinna zostać zaakceptowana, np.. aero i .xn--jxalpdlp.
- numery portów powinny być dozwolone.
- adresy URL muszą być dozwolone w normalnych kontekstach zdań. Na przykład w "wizycie stackoverflow.com.", finał kropka nie jest częścią adresu URL.
- prawdopodobnie chcesz zezwolić na adresy URL "https://", a być może również na inne.
- jak zawsze podczas wyświetlania tekstu dostarczonego przez użytkownika w HTML, chcesz zapobiec skryptom cross-Site scripting (XSS). Ponadto, będziesz chciał, aby ampersands w adresach URL był poprawnie unikany jako &.
- prawdopodobnie nie potrzebujesz wsparcia dla adresów IPv6.
- Edit : Jak wspomniano w komentarzach, obsługa adresów e-mail jest zdecydowanie plus.
- Edit : obsługiwane jest tylko wprowadzanie zwykłego tekstu – znaczniki HTML w wejściu nie powinny być honorowane. (Wersja Bitbucket obsługuje wejście HTML.)
Edytuj : Sprawdź Bitbucket, aby zobaczyć najnowszą wersję, z obsługą adresów e-mail, uwierzytelnionych adresów URL, adresów URL w cudzysłowach i nawiasach, wprowadzania HTML, a także zaktualizowanej listy TLD.
prosimy zgłaszać błędy i prośby o ulepszenia za pomocą narzędzia Bitbucket issue tracker. Są łatwiejsze do śledzenia w ten sposób (i nie zaśmiecać obszaru komentarzy).
Oto moje ujęcie:
<?php
$text = <<<EOD
Here are some URLs:
stackoverflow.com/questions/1188129/pregreplace-to-detect-html-php
Here's the answer: http://www.google.com/search?rls=en&q=42&ie=utf-8&oe=utf-8&hl=en. What was the question?
A quick look at http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax is helpful.
There is no place like 127.0.0.1! Except maybe http://news.bbc.co.uk/1/hi/england/surrey/8168892.stm?
Ports: 192.168.0.1:8080, https://example.net:1234/.
Beware of Greeks bringing internationalized top-level domains: xn--hxajbheg2az3al.xn--jxalpdlp.
And remember.Nobody is perfect.
<script>alert('Remember kids: Say no to XSS-attacks! Always HTML escape untrusted input!');</script>
EOD;
$rexProtocol = '(https?://)?';
$rexDomain = '((?:[-a-zA-Z0-9]{1,63}\.)+[-a-zA-Z0-9]{2,63}|(?:[0-9]{1,3}\.){3}[0-9]{1,3})';
$rexPort = '(:[0-9]{1,5})?';
$rexPath = '(/[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]*?)?';
$rexQuery = '(\?[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?';
$rexFragment = '(#[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?';
// Solution 1:
function callback($match)
{
// Prepend http:// if no protocol specified
$completeUrl = $match[1] ? $match[0] : "http://{$match[0]}";
return '<a href="' . $completeUrl . '">'
. $match[2] . $match[3] . $match[4] . '</a>';
}
print "<pre>";
print preg_replace_callback("&\\b$rexProtocol$rexDomain$rexPort$rexPath$rexQuery$rexFragment(?=[?.!,;:\"]?(\s|$))&",
'callback', htmlspecialchars($text));
print "</pre>";
- aby poprawnie uciec znaków
- Jak pokazuje "i pamiętaj.Nikt nie jest doskonały."linia (w której pamiętaj.Nikt nie jest traktowany jako URL, ze względu na brak miejsca), dalsze sprawdzanie na ważne domeny najwyższego poziomu mogą być w porządku.
Edit: poniższy kod rozwiązuje dwa powyższe problemy, ale jest nieco bardziej gadatliwy, ponieważ mniej więcej ponownie implementuję preg_replace_callback
używając preg_match
.
// Solution 2:
$validTlds = array_fill_keys(explode(" ", ".aero .asia .biz .cat .com .coop .edu .gov .info .int .jobs .mil .mobi .museum .name .net .org .pro .tel .travel .ac .ad .ae .af .ag .ai .al .am .an .ao .aq .ar .as .at .au .aw .ax .az .ba .bb .bd .be .bf .bg .bh .bi .bj .bm .bn .bo .br .bs .bt .bv .bw .by .bz .ca .cc .cd .cf .cg .ch .ci .ck .cl .cm .cn .co .cr .cu .cv .cx .cy .cz .de .dj .dk .dm .do .dz .ec .ee .eg .er .es .et .eu .fi .fj .fk .fm .fo .fr .ga .gb .gd .ge .gf .gg .gh .gi .gl .gm .gn .gp .gq .gr .gs .gt .gu .gw .gy .hk .hm .hn .hr .ht .hu .id .ie .il .im .in .io .iq .ir .is .it .je .jm .jo .jp .ke .kg .kh .ki .km .kn .kp .kr .kw .ky .kz .la .lb .lc .li .lk .lr .ls .lt .lu .lv .ly .ma .mc .md .me .mg .mh .mk .ml .mm .mn .mo .mp .mq .mr .ms .mt .mu .mv .mw .mx .my .mz .na .nc .ne .nf .ng .ni .nl .no .np .nr .nu .nz .om .pa .pe .pf .pg .ph .pk .pl .pm .pn .pr .ps .pt .pw .py .qa .re .ro .rs .ru .rw .sa .sb .sc .sd .se .sg .sh .si .sj .sk .sl .sm .sn .so .sr .st .su .sv .sy .sz .tc .td .tf .tg .th .tj .tk .tl .tm .tn .to .tp .tr .tt .tv .tw .tz .ua .ug .uk .us .uy .uz .va .vc .ve .vg .vi .vn .vu .wf .ws .ye .yt .yu .za .zm .zw .xn--0zwm56d .xn--11b5bs3a9aj6g .xn--80akhbyknj4f .xn--9t4b11yi5a .xn--deba0ad .xn--g6w251d .xn--hgbk6aj7f53bba .xn--hlcj6aya9esc7a .xn--jxalpdlp .xn--kgbechtv .xn--zckzah .arpa"), true);
$position = 0;
while (preg_match("{\\b$rexProtocol$rexDomain$rexPort$rexPath$rexQuery$rexFragment(?=[?.!,;:\"]?(\s|$))}", $text, &$match, PREG_OFFSET_CAPTURE, $position))
{
list($url, $urlPosition) = $match[0];
// Print the text leading up to the URL.
print(htmlspecialchars(substr($text, $position, $urlPosition - $position)));
$domain = $match[2][0];
$port = $match[3][0];
$path = $match[4][0];
// Check if the TLD is valid - or that $domain is an IP address.
$tld = strtolower(strrchr($domain, '.'));
if (preg_match('{\.[0-9]{1,3}}', $tld) || isset($validTlds[$tld]))
{
// Prepend http:// if no protocol specified
$completeUrl = $match[1][0] ? $url : "http://$url";
// Print the hyperlink.
printf('<a href="%s">%s</a>', htmlspecialchars($completeUrl), htmlspecialchars("$domain$port$path"));
}
else
{
// Not a valid URL.
print(htmlspecialchars($url));
}
// Continue text parsing from after the URL.
$position = $urlPosition + strlen($url);
}
// Print the remainder of the text.
print(htmlspecialchars(substr($text, $position)));
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-11 18:21:51
Oto coś, co znalazłem, które jest wypróbowane i przetestowane
function make_links_blank($text)
{
return preg_replace(
array(
'/(?(?=<a[^>]*>.+<\/a>)
(?:<a[^>]*>.+<\/a>)
|
([^="\']?)((?:https?|ftp|bf2|):\/\/[^<> \n\r]+)
)/iex',
'/<a([^>]*)target="?[^"\']+"?/i',
'/<a([^>]+)>/i',
'/(^|\s)(www.[^<> \n\r]+)/iex',
'/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)
(\\.[A-Za-z0-9-]+)*)/iex'
),
array(
"stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\">\\2</a>\\3':'\\0'))",
'<a\\1',
'<a\\1 target="_blank">',
"stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\">\\2</a>\\3':'\\0'))",
"stripslashes((strlen('\\2')>0?'<a href=\"mailto:\\0\">\\0</a>':'\\0'))"
),
$text
);
}
U mnie działa. I działa na e-maile i adresy URL, Przepraszam, że odpowiadam na moje własne pytanie. :(
Ale tylko ten działa
Oto link gdzie go znalazłem: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_21878567.html
Sry z góry za to, że jest to wymiana ekspertów.Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-27 14:24:38
Wy guyz mówicie o postępach i skomplikowanych rzeczach, które są dobre w niektórych sytuacjach, ale przede wszystkim potrzebujemy prostego, nieostrożnego rozwiązania. Może po prostu to?
preg_replace('/(http[s]{0,1}\:\/\/\S{4,})\s{0,}/ims', '<a href="$1" target="_blank">$1</a> ', $text_msg);
Po prostu spróbuj i daj mi znać, jaki szalony url nie spełnia.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-20 10:13:09
Oto kod wykorzystujący wyrażenia regularne w funkcji
<?php
//Function definations
function MakeUrls($str)
{
$find=array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`si','`((?<!//)(www\.\S+[[:alnum:]]/?))`si');
$replace=array('<a href="$1" target="_blank">$1</a>', '<a href="http://$1" target="_blank">$1</a>');
return preg_replace($find,$replace,$str);
}
//Function testing
$str="www.cloudlibz.com";
$str=MakeUrls($str);
echo $str;
?>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-11 18:46:11
Używam tej funkcji, działa dla mnie
function AutoLinkUrls($str,$popup = FALSE){
if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)){
$pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
for ($i = 0; $i < count($matches['0']); $i++){
$period = '';
if (preg_match("|\.$|", $matches['6'][$i])){
$period = '.';
$matches['6'][$i] = substr($matches['6'][$i], 0, -1);
}
$str = str_replace($matches['0'][$i],
$matches['1'][$i].'<a href="http'.
$matches['4'][$i].'://'.
$matches['5'][$i].
$matches['6'][$i].'"'.$pop.'>http'.
$matches['4'][$i].'://'.
$matches['5'][$i].
$matches['6'][$i].'</a>'.
$period, $str);
}//end for
}//end if
return $str;
}//end AutoLinkUrls
Wszystkie napisy idą do - http://snipplr.com/view/68586/
Smacznego!Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-02 15:26:34
Ten RegEx powinien pasować do każdego linku z wyjątkiem tych nowych domen toplevel 3+...
{ \\b # Match the leading part (proto://hostname, or just hostname) ( # http://, or https:// leading part (https?)://[-\\w]+(\\.\\w[-\\w]*)+ | # or, try to find a hostname with more specific sub-expression (?i: [a-z0-9] (?:[-a-z0-9]*[a-z0-9])? \\. )+ # sub domains # Now ending .com, etc. For these, require lowercase (?-i: com\\b | edu\\b | biz\\b | gov\\b | in(?:t|fo)\\b # .int or .info | mil\\b | net\\b | org\\b | [a-z][a-z]\\.[a-z][a-z]\\b # two-letter country code ) ) # Allow an optional port number ( : \\d+ )? # The rest of the URL is optional, and begins with / ( / # The rest are heuristics for what seems to work well [^.!,?;"\\'()\[\]\{\}\s\x7F-\\xFF]* ( [.!,?]+ [^.!,?;"\\'()\\[\\]\{\\}\s\\x7F-\\xFF]+ )* )? }ix
Nie jest napisany przeze mnie, nie jestem do końca pewien, skąd go mam, przepraszam, że nie mogę się pochwalić...
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-27 13:29:00
To powinno dać Ci adresy e-mail:
$string = "bah bah [email protected] foo";
$match = preg_match('/[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+/', $string, $array);
print_r($array);
// outputs:
Array
(
[0] => [email protected]
)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-27 13:41:31
Wiem, że ta odpowiedź została przyjęta i że to pytanie jest dość stare, ale może być przydatne dla innych osób szukających innych implementacji.
Jest to zmodyfikowana wersja kodu zamieszczonego przez: Angel.King.47 dnia 27 lipca 09:
$text = preg_replace(
array(
'/(^|\s|>)(www.[^<> \n\r]+)/iex',
'/(^|\s|>)([_A-Za-z0-9-]+(\\.[A-Za-z]{2,3})?\\.[A-Za-z]{2,4}\\/[^<> \n\r]+)/iex',
'/(?(?=<a[^>]*>.+<\/a>)(?:<a[^>]*>.+<\/a>)|([^="\']?)((?:https?):\/\/([^<> \n\r]+)))/iex'
),
array(
"stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a> \\3':'\\0'))",
"stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a> \\4':'\\0'))",
"stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\" target=\"_blank\">\\3</a> ':'\\0'))",
),
$text
);
Zmiany:
- usunąłem Zasady # 2 i # 3 (nie jestem pewien, w jakich sytuacjach są przydatne).
- usunięto parsowanie poczty e-mail, ponieważ naprawdę jej nie potrzebuję.
- dodałem jeszcze jedną regułę, która umożliwia rozpoznawanie adresów URL w forma: [domena]/* (bez www). Na przykład: "example.com/faq /" (Multiple TLD: domain.{2-3}.{2-4}/)
- podczas parsowania łańcuchów zaczynających się od" http://", usuwa je z etykiety łącza.
- dodano "target= '_blank' " do wszystkich linków.
- adresy URL można podać tuż po dowolnym (?) tag. Na przykład: www.example.com
Jak stwierdził "Søren Løvborg", funkcja ta nie wymywa adresów URL. Próbowałem jego / jej klasy, ale to po prostu nie działa tak, jak się spodziewałem (jeśli nie ufasz Użytkowników, następnie najpierw wypróbuj jego / jej kod).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-04-05 05:32:51
Jak wspomniałem w jednym z komentarzy powyżej mój VPS, który działa php 7, zaczął emitting warnings Warning: preg_replace (): modyfikator / e nie jest już obsługiwany, użyj preg_replace_callback zamiast. Bufor po zastąpieniu był pusty / fałszywy.
Przepisałem kod i wprowadziłem kilka ulepszeń. Jeśli uważasz, że powinieneś być w sekcji autor, możesz edytować komentarz nad nazwą funkcji make_links_blank. Celowo nie używam zamykanie php ?> aby uniknąć wstawiania białych znaków na wyjściu.
<?php
class App_Updater_String_Util {
public static function get_default_link_attribs( $regex_matches = [] ) {
$t = ' target="_blank" ';
return $t;
}
/**
* App_Updater_String_Util::set_protocol();
* @param string $link
* @return string
*/
public static function set_protocol( $link ) {
if ( ! preg_match( '#^https?#si', $link ) ) {
$link = 'http://' . $link;
}
return $link;
}
/**
* Goes through text and makes whatever text that look like a link an html link
* which opens in a new tab/window (by adding target attribute).
*
* Usage: App_Updater_String_Util::make_links_blank( $text );
*
* @param str $text
* @return str
* @see http://stackoverflow.com/questions/1188129/replace-urls-in-text-with-html-links
* @author Angel.King.47 | http://dashee.co.uk
* @author Svetoslav Marinov (Slavi) | http://orbisius.com
*/
public static function make_links_blank( $text ) {
$patterns = [
'#(?(?=<a[^>]*>.+?<\/a>)
(?:<a[^>]*>.+<\/a>)
|
([^="\']?)((?:https?|ftp):\/\/[^<> \n\r]+)
)#six' => function ( $matches ) {
$r1 = empty( $matches[1] ) ? '' : $matches[1];
$r2 = empty( $matches[2] ) ? '' : $matches[2];
$r3 = empty( $matches[3] ) ? '' : $matches[3];
$r2 = empty( $r2 ) ? '' : App_Updater_String_Util::set_protocol( $r2 );
$res = ! empty( $r2 ) ? "$r1<a href=\"$r2\">$r2</a>$r3" : $matches[0];
$res = stripslashes( $res );
return $res;
},
'#(^|\s)((?:https?://|www\.|https?://www\.)[^<>\ \n\r]+)#six' => function ( $matches ) {
$r1 = empty( $matches[1] ) ? '' : $matches[1];
$r2 = empty( $matches[2] ) ? '' : $matches[2];
$r3 = empty( $matches[3] ) ? '' : $matches[3];
$r2 = ! empty( $r2 ) ? App_Updater_String_Util::set_protocol( $r2 ) : '';
$res = ! empty( $r2 ) ? "$r1<a href=\"$r2\">$r2</a>$r3" : $matches[0];
$res = stripslashes( $res );
return $res;
},
// Remove any target attribs (if any)
'#<a([^>]*)target="?[^"\']+"?#si' => '<a\\1',
// Put the target attrib
'#<a([^>]+)>#si' => '<a\\1 target="_blank">',
// Make emails clickable Mailto links
'/(([\w\-]+)(\\.[\w\-]+)*@([\w\-]+)
(\\.[\w\-]+)*)/six' => function ( $matches ) {
$r = $matches[0];
$res = ! empty( $r ) ? "<a href=\"mailto:$r\">$r</a>" : $r;
$res = stripslashes( $res );
return $res;
},
];
foreach ( $patterns as $regex => $callback_or_replace ) {
if ( is_callable( $callback_or_replace ) ) {
$text = preg_replace_callback( $regex, $callback_or_replace, $text );
} else {
$text = preg_replace( $regex, $callback_or_replace, $text );
}
}
return $text;
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-14 10:35:19
Coś w rodzaju:
<?php
if(preg_match('@^http://(.*)\s|$@g', $textarea_url, $matches)) {
echo '<a href=http://", $matches[1], '">', $matches[1], '</a>';
}
?>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-27 13:30:11
To class
zmienia adresy URL na tekst i zachowując domowy adres URL w takim stanie, w jakim jest. Mam nadzieję, że to pomoże i zaoszczędzi czas dla Ciebie.Smacznego.
class RegClass
{
function preg_callback_url($matches)
{
//var_dump($matches);
//Get the matched URL text <a>text</a>
$text = $matches[2];
//Get the matched URL link <a href ="http://www.test.com">text</a>
$url = $matches[1];
if($url=='href ="http://www.test.com"'){
//replace all a tag as it is
return '<a href='.$url.' rel="nofollow"> '.$text.' </a>';
}else{
//replace all a tag to text
return " $text " ;
}
}
function ParseText($text){
$text = preg_replace( "/www\./", "http://www.", $text );
$regex ="/http:\/\/http:\/\/www\./"
$text = preg_replace( $regex, "http://www.", $text );
$regex2 = "/https:\/\/http:\/\/www\./";
$text = preg_replace( $regex2, "https://www.", $text );
return preg_replace_callback('/<a\s(.+?)>(.+?)<\/a>/is',
array( &$this, 'preg_callback_url'), $text);
}
}
$regexp = new RegClass();
echo $regexp->ParseText($text);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-21 12:06:00
Jeśli chcesz zaufać IANA, możesz uzyskać aktualną listę obsługiwanych przez siebie domen TLD, takich jak:
$validTLDs =
explode("\n", file_get_contents('http://data.iana.org/TLD/tlds-alpha-by-domain.txt')); //get the official list of valid tlds
array_shift($validTLDs); //throw away first line containing meta data
array_pop($validTLDs); //throw away last element which is empty
Sprawia, że rozwiązanie Sørena Løvborga #2 jest nieco mniej gadatliwe i oszczędza ci kłopotów z aktualizacją listy, obecnie nowe TLD są wyrzucane tak beztrosko;)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-03-05 04:53:35
To zadziałało dla mnie (zamieniło jedną z odpowiedzi na funkcję PHP)
function make_urls_from_text ($text){
return preg_replace('/(http[s]{0,1}\:\/\/\S{4,})\s{0,}/ims', '<a href="$1" target="_blank">$1 </a>', $text);
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-02 18:18:55
To powinno dostać twój twitter uchwyt bez dotykania na e-mail /(?.])) @([A-Za-z]+[a-Za-z0-9]+)/i
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-14 10:12:29
Chociaż dopasowanie pełnej specyfikacji adresu url jest trudne, oto Wyrażenie regularne, które generalnie wykonuje dobrą robotę:
([\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?)
Aby użyć tego w preg_replace, musisz z tego uciec. TAK:
$pattern = "/([\\w-]+(\\.[\\w-]+)*@([a-z0-9-]+(\\.[a-z0-9-]+)*?\\.[a-z]{2,6}|(\\d{1,3}\\.){3}\\d{1,3})(:\\d{4})?)/";
$replaced_texttext = preg_replace($pattern, '<a href="$0" title="$0">$0</a>', $text);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-27 14:11:18