1. sayfa
$text = "Bu bir cümledir.(Resim 1) Bu ikinci cümledir.(Resim 2)";$yenitext = preg_replace("/\(Resim ([0-9]+)\)/", "<a data-test="test" rel="nofollow" style="word-wrap: break-word; text-decoration: underline;" target="_blank" onclick="return dhExternalLinkRedirect(this)" href="/ExternalLinkRedirect?module=pgdcode&messageId=130974707&url=#" onclick="$('.popup-gallery').magnificPopup('open', $1-1);" data-href="#" onclick="$('.popup-gallery').magnificPopup('open', $1-1);">$0</a>", $text);
quote:<?php function link_ekle($eslesmeler) { $parantezler = array("(",")"); //Bu kısım RegExp içinde halledilebilir. $tmp="<a href=\"#\" onclick=\"$('.popup-gallery').magnificPopup('open'," . ($eslesmeler[1]-1) . ");\">" . str_replace($parantezler, '', $eslesmeler[0]) . "</a>\n"; return $tmp; } $metin = "Bu bir cumledir.(Resim 1) Bu ikinci cumledir.(Resim 2)"; echo preg_replace_callback("|\(Resim ([0-9]+)\)|", "link_ekle", $metin); ?>
Yukarıdaki kodda
Resim 1 yerine <a data-test="test" rel="nofollow" style="word-wrap: break-word; text-decoration: underline;" target="_blank" onclick="return dhExternalLinkRedirect(this)" href="/ExternalLinkRedirect?module=pgdcode&messageId=130974707&url=#" onclick="$('.popup-gallery').magnificPopup('open', 0);" data-href="#" onclick="$('.popup-gallery').magnificPopup('open', 0);">Resim 1</a>,
Resim 2 yerine <a data-test="test" rel="nofollow" style="word-wrap: break-word; text-decoration: underline;" target="_blank" onclick="return dhExternalLinkRedirect(this)" href="/ExternalLinkRedirect?module=pgdcode&messageId=130974707&url=#" onclick="$('.popup-gallery').magnificPopup('open', 1);" data-href="#" onclick="$('.popup-gallery').magnificPopup('open', 1);">Resim 2</a> elde etmek istiyorum
ancak mesela
Resim 2 yerine <a data-test="test" rel="nofollow" style="word-wrap: break-word; text-decoration: underline;" target="_blank" onclick="return dhExternalLinkRedirect(this)" href="/ExternalLinkRedirect?module=pgdcode&messageId=130974707&url=#" onclick="$('.popup-gallery').magnificPopup('open', 2-1);" data-href="#" onclick="$('.popup-gallery').magnificPopup('open', 2-1);">Resim 2</a> elde ediyorum.
Burda 1 çıkarma işlemini nasıl yaparım. Ustalar bakabilir mi? Teşekkürler.
< Bu mesaj bu kişi tarafından değiştirildi stbolen -- 20 Ocak 2018; 23:56:23 >