Citat:
LaMiniX je napisao:
Ali meni treba example :)
Ja ne biti lenj. Ja otici na stranicu:
http://www.php.net/manual/en/function.ereg.php
Ja tamo videti:
editor@mylamb.com
01-Sep-2000 11:38
FWIW - I allow users to post URLs right on the site. However, sometimes they want the HTTP:// business. Sometimes not. Here's a little function I find handy:
function stripHTTP($url)
{
if (eregi('(^http[s]*:[/]+)(.*)', $url, $x))
return $x[2];
return $url;
}
dalje,
carlos_aT_radiumsystems_DoT_com
10-Oct-2001 03:53
Just to extend an example about stripping hyperlinks in htmls from user comments above, here it goes an regexp to find anything in href="xx", javascript included.
$regexp = "(< *[aA] *)([^>]*)([hH][rR][eE][fF] *= *)((\"[^\">]*\")|('[^'>]*')|[^> ]*)([^>]*>)";
Na strani:
http://www.php.net/manual/en/function.ereg-replace.php
IMA BAS ONO STO TI HOCES, na nekoliko mesta (razlicito):
rink@springer.cx
27-Feb-2000 12:09
Code code below will change every
http://(something) reference to a hyperlink! Yay!
<pre>$it = ereg_replace("http://(([A-Za-z0-9.\-])*)([a-zA-Z0-9])", "<a href=\"\\0
\">\\0</a>",$it);</pre>
Enjoy!
Dalje,
03-Apr-2000 02:11
I wrote the following regex to convert text in hyperlinks. I think works slightly better than the one already posted.
$tmp = ereg_replace("http://(([A-Za-z0-9.\-])+)([a-zA-Z0-9])((/(([a-zA-Z0-9])*))*)((.([a-zA-Z0-9])+)*)", "<a href=\"\\0\">\\0</a>",$tmp);
, jos:
superdoc@shinbiro.com
14-Apr-2000 12:58
convert in hyperlink...how about this?
$tmp = ereg_replace("((ftp://)|(http://))(([[:alnum:]]|[[:punct:]])*)", "<a href=\"\\0\">\\0</a>",$tmp);
Ovaj je bas detaljan:
ckrempea@sfu.ca
03-Jan-2001 05:41
I've seen various notes added for turning URLs (in text) into hyperlinks.
Many of them seem to put [[::space:]] before and after to find it. But this will NOT work if the link (or whatever you are looking for) starts at the **very beginning** of the string; or the **very end** of the string.
What is needed is to look for the (^|[[:space:]]) at the beginning; and the ([[:space:]]|$) at the end.
For example here are a few types of URLs (http, https, and ftp) that are converted...
$content = ereg_replace("(^|[[:space:]])(http://[^[:space:]]{1,})([[:space:]]|$)", "\\1<a href=\"\\2\">\\2</a>\\3", $content);
$content = ereg_replace("(^|[[:space:]])(https://[^[:space:]]{1,})([[:space:]]|$)", "\\1<a href=\"\\2\">\\2</a>\\3", $content);
$content = ereg_replace("(^|[[:space:]])(ftp://[^[:space:]]{1,})([[:space:]]|$)", "\\1<a href=\"\\2\">\\2</a>\\3", $content);
And, since I didn't notice it mentioned above,... you can create smileys (for a bulletin board or whatever) with...
$content = ereg_replace('(^|[[:space:]]):-\)([[:space:]]|$)', "\\1<img src=\"image/smiley-smile.gif\">\\2", $content);
$content = ereg_replace('(^|[[:space:]]):-\(([[:space:]]|$)', "\\1<img src=\"image/smiley-frown.gif\">\\2", $content);
(For converting :-) and :-( .. You'll have to set the image sources -- the `src' attribute in the `img' tag -- to whatever you smiley image files are.)
Of course you can use this technique for whatever you want. (Not just hyperlinks and smileys.) (For example, like censoring out swearing, for a kid-safe site,... or whatever). Just use...
(^|[[:space:]])
... for the beginning. And...
([[:space:]]|$)
...for the end
-----
Charles Iliya Krempeaux
ckrempea@sfu.ca
03-Jan-2001 05:48
I just want to make a note to what I said above.
NOTE, that above I am using ([[:space:]]|$) in a single quote style string. For example...
'([[:space:]]|$)'
NOT a double quote string. You should escape out the dollar sign, $, if a double quote string. (Or else PHP will try to do a variable replacement.)
itd, itd, sam pogledaj na tim stranama...
Jel' dosta primera? &:)
E odoh ja sad napokon kucici mojoj....
Kad sve ostalo zakaže, pročitaj uputstvo...