Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
Regex HELP

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side
View previous topic :: View next topic  
Author Message
Tedius



Joined: 22 Dec 2003
Posts: 149
Location: Zagreb

PostPosted: 18.05.2005 10:59    Post subject: Regex HELP Add user to your forum ignore list Reply with quote

Bok ljudi, evo mučim se već dva dana i nikako da otkrijem negaciju kak spada.
Naime treba mi regex koji traži zadanu riječ, ali da se ta riječ ne nalazi unutar linka dakle npr. <a> taga.

Do sada sam došao do ovog što je dijametralno suprotno od onog što mi treba, al sam mislio da ću moći to pretvoriti u svojevrsnu negaciju... Embarassed

Code:
/(<a[^>]*>.*\bNEKARIJEC\b.*<\/a>)/i


Da još jedamput prođem kroz cijeli problem, treba mi zapravo regex u kombinaciji sa preg_replace-om koji bi određene riječi pretvarao u zadani link, samo ako riječ nije unutar linka. Jasno? Laughing
Back to top
View user's profile Send private message Visit poster's website
Tedius



Joined: 22 Dec 2003
Posts: 149
Location: Zagreb

PostPosted: 18.05.2005 11:28    Post subject: Add user to your forum ignore list Reply with quote

I opet Google, ovaj put sa malo boljim rezultatom

http://www.textism.com/tools/google_hilite/

...no još uvijek nisam zadovoljan Confused
Back to top
View user's profile Send private message Visit poster's website
zytzagoo
mi3.crew


Joined: 25 Aug 2003
Posts: 1842
Location: Zagreb, Hrvatska

PostPosted: 18.05.2005 14:23    Post subject: Add user to your forum ignore list Reply with quote

Quick search na google-u izbacio ovo:
http://www.webmasterworld.com/forum88/5742.htm

U slucaju da link ne radi, evo kôda sa te stranice:
Code:
<?php

// text
$text = '<a href="http://www.php.net">php</a> is a web programming language . A popular pHp program is phpmyadmin. See http://www.php.net.';

// Word to search for
$lookfor = 'php';

// regexp pattern
$pattern = '#(?!<.*?)(?!<a)(\\b'.$lookfor.'\\b)(?!<\/a>)(?![^<>]*?>)#i';
// (?!<a) (?!<\/a>) - prevents text in between <a></a>
// i (at the end) - case insensitive search

// store all matches in an array
preg_match_all ($pattern, $text, $matches);

// remove duplicate entries
$matches=array_unique($matches[0]);

// Loop to replace entries - case sensitive
foreach ($matches as $match)
{
$pattern = '#(?!<.*?)(?!<a)(\\b'.$match.'\\b)(?!<\/a>)(?![^<>]*?>)#';

$replacement = '<a href="http://linksomewhere"><span style="background: yellow">'.$match.'</span></a>';

$text = preg_replace($pattern, $replacement, $text );
}

echo $text;

?>


HTH
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Tedius



Joined: 22 Dec 2003
Posts: 149
Location: Zagreb

PostPosted: 18.05.2005 14:41    Post subject: Add user to your forum ignore list Reply with quote

Tnx Zyt, nekako sam imao osjecaj da ces se ti prvi javiti za ovakve stvari Wink
već sam upotrijebio prethodnu skriptu, ali mi se ovako na prvi pogled cini da bi ova mogla bolje raditi, pa idem unijeti promjenu da vidim kak ce se ponasat.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group