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
PHP & regex - Problem

 
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
macros



Joined: 03 Jan 2004
Posts: 23
Location: Zagreb, HR

PostPosted: 31.05.2004 11:27    Post subject: PHP & regex - Problem Add user to your forum ignore list Reply with quote

Imam mali problem: Htio bih text koji se nalazi izmedju zvjezdica stavit u <strong></strong> tagove...

npr.
Ja sam *jedan* mali *piroman*.
se pretvori u
Ja sam <strong>jedan</strong> mali <strong>piroman</strong>.

Za to sam napisao ovu naredbu:

$text = ereg_replace('(\*){1}(.*)(\*){1}', '<strong>\2</strong>', $text;

Dok se takav tekst medju zvjezdicama pojavljuje samo jednom sve je ok... Ali cim se pojavljuje dva ili vise puta (kao u primjeru) sve bude smuljano...

What's wrong?

_________________
Es gibt nichts stilleres als eine geladene Kanone. - Heinrich Heine
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: 31.05.2004 11:51    Post subject: Add user to your forum ignore list Reply with quote

Nisam neki strucnjak, i ovo se vjerojatno moze i bolje napisati da obuhvaca vise mogucih slucajeva, ali za ovu tvoju recenicu radi:
Code:
$text = preg_replace("/\*(.*?)\*/","<strong>\\1</strong>",$text);


Koristim preg_replace() zato jer je cesto brzi, i koristi perl-like sintaksu koja mi je bliza i poznatija...

_________________
[+]I[+]am[+]my[+]own[+]religion[+]
Back to top
View user's profile Send private message Visit poster's website Twitter profile
macros



Joined: 03 Jan 2004
Posts: 23
Location: Zagreb, HR

PostPosted: 31.05.2004 12:04    Post subject: Add user to your forum ignore list Reply with quote

Thanx, Smile
U medjuvremenu sam i sam uspio... Problem je bio sto bi moj kod iz prvog teksta sve izmedju prve i zadnje zvjezdice stavio pod <strong> tag... sad sam samo jos stavio da tekst koji se treba boldat ne smije imat * u sebi...

tj.

$text = ereg_replace('(\*)([^\*]*)(\*)', '<strong>\2</strong>', $text);

_________________
Es gibt nichts stilleres als eine geladene Kanone. - Heinrich Heine
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