Zamjena dijela teksta sa linkom

Može li mi netko pomoći? Ne znam kako da napravim pretragu nekoga teksta iz baze
i da iz toga teksta izdvojim adrese unesene u njega i prikažem ih kasnije kao link.

Nakon što queryem dohvatim tekst, mogu li nekako sa preg_match_all () ili nekom
drugom funkciom naći dio teksta koji u sebi ima http:// ili www. i zamjenit ga to jest taj dio ispisat kao i ovdje www.adresa.com unutar toga cijelog teksa?
:0ci:

Neznam ima li funkcija (vjerojatno nema, al ja san ovca u php-u pa uzmi sa rezervon.)
Imaš funkciju strpos (tek od php5, stariji nemaju). ona ti dade početnu poziciju niza “http”. dalje kroz petlju tražiš blenk i kad ga dobiješ to je kraj URL-a. Pokupiš ga sa substr, a daljnja zamjena je stvar tvoje kreativnosti. I znanja naravno! Nadam se da ga imaš više od mene!!
Dodatak: Ako strpos ima mogućnost traženja od određene pozicije (koju ti je dao za “http”) petlja za traženje blenka (praznog polja) ne treba već poziciju blenka dobiješ opet strpos funkcijom.

Hehe, nisan ti ni ja ništa bolji od ovce… Recimo da “programiram” možda mjesec dana (čitaj = učim se programirat).
Evo zahvaljujuć tebi uspio sam nešto napravit i radi. Pa ako će kome trebat neka se posluži a i nadam se da će ovi iskusniji u PHP-u ukazati na greške i možda udjelit kakav savjet.

Probaj i ovako:

<span class="syntaxdefault"></span><span class="syntaxkeyword">function&nbsp;</span><span class="syntaxdefault">linkit</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$tekst</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$target&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxstring">"_blank"</span><span class="syntaxkeyword">)&nbsp;{<br /></span><span class="syntaxdefault">$url_html&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">preg_replace</span><span class="syntaxkeyword">(<br /></span><span class="syntaxstring">'/(?<!S)((http(s?):\/\/)|( www.))+( [\w.1-9\&=#?\-~%;\/]+)/'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxstring">'<a&nbsp;target="'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$target</span><span class="syntaxkeyword">.</span><span class="syntaxstring">'"&nbsp;href="http$3://$4$5">http$3://$4$5</a>'</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$tekst</span><span class="syntaxkeyword">);<br />return&nbsp;(</span><span class="syntaxdefault">$url_html</span><span class="syntaxkeyword">);<br />}&nbsp;</span><span class="syntaxdefault"></span>

Primer:

$text = linkit("Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum http://lipsum.com has been the industry's standard dummy text ever since
the 1500s, when an unknown printer took a galley of type and scrambled it to make a type 
specimen book. 
It has survived not only five centuries, but also the leap into electronic typesetting, 
remaining essentially unchanged. 
It was popularised in the 1960s with the release of Letraset sheets containing 
Lorem Ipsum http://lipsum.com passages, and more recently with desktop publishing software
like Aldus PageMaker including versions of Lorem Ipsum.")

Rezultat:

[quote=""]Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum
http://lipsum.com
has been the industry’s standard dummy text ever since
the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing
Lorem Ipsum
http://lipsum.com
passages, and more recently with desktop publishing software
like Aldus PageMaker including versions of Lorem Ipsum.[/quote]

[quote=“Piky”]Hehe, nisan ti ni ja ništa bolji od ovce… Recimo da “programiram” možda mjesec dana (čitaj = učim se programirat).
Evo zahvaljujuć tebi uspio sam nešto napravit i radi. Pa ako će kome trebat neka se posluži a i nadam se da će ovi iskusniji u PHP-u ukazati na greške i možda udjelit kakav savjet.

:doki:

[quote=“ivan79”]Probaj i ovako:

<span class="syntaxdefault"></span><span class="syntaxkeyword">function&nbsp;</span><span class="syntaxdefault">linkit</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$tekst</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$target&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxstring">"_blank"</span><span class="syntaxkeyword">)&nbsp;{<br /></span><span class="syntaxdefault">$url_html&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">preg_replace</span><span class="syntaxkeyword">(<br /></span><span class="syntaxstring">'/(?<!S)((http(s?):\/\/)|( www.))+( [\w.1-9\&=#?\-~%;\/]+)/'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxstring">'<a&nbsp;target="'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$target</span><span class="syntaxkeyword">.</span><span class="syntaxstring">'"&nbsp;href="http$3://$4$5">http$3://$4$5</a>'</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$tekst</span><span class="syntaxkeyword">);<br />return&nbsp;(</span><span class="syntaxdefault">$url_html</span><span class="syntaxkeyword">);<br />}&nbsp;</span><span class="syntaxdefault"></span>
:[/quote]Ovo ni uz najbolju volju nemogu razumiti, al ako radi svaka čast!!

[quote=“ivan79”]Probaj i ovako:

<span class="syntaxdefault"></span><span class="syntaxkeyword">function&nbsp;</span><span class="syntaxdefault">linkit</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$tekst</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$target&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxstring">"_blank"</span><span class="syntaxkeyword">)&nbsp;{<br /></span><span class="syntaxdefault">$url_html&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">preg_replace</span><span class="syntaxkeyword">(<br /></span><span class="syntaxstring">'/(?<!S)((http(s?):\/\/)|( www.))+( [\w.1-9\&=#?\-~%;\/]+)/'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxstring">'<a&nbsp;target="'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$target</span><span class="syntaxkeyword">.</span><span class="syntaxstring">'"&nbsp;href="http$3://$4$5">http$3://$4$5</a>'</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$tekst</span><span class="syntaxkeyword">);<br />return&nbsp;(</span><span class="syntaxdefault">$url_html</span><span class="syntaxkeyword">);<br />}&nbsp;</span><span class="syntaxdefault"></span>
[/quote]

Probao sam ovo ali mi ne radi.


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Webmaster.Ninja