Jump to content
php.lv forumi

BB kodu problēma


emsy

Recommended Posts

function coloris($value) {
$value = preg_replace('/(\[color=)(.+?)(\])(.+)(\[\/color\])/', '<span style=\'color:\\2;\'>\\4</span>', $value);
return $value;
}

 

Problēma tāda, ka ja bbkodi ir izmantoti vairāki, un starp viņiem nav \n, tad viss tiek tā kā samests kopā.

 

Piem.

Input:

asd[color=#000]asd[/color]asd[color=#fff]asd[/color]asd

[color=#000]asd[/color]

 

Output:

asd<span style='color:#000;'>asd[/color]asd[color=#fff]asd</span>asd

<span style='color:#000;'>asd</span>

 

Cik zinu (.+) neakceptē \n tāpēc bbkodi kuri ir citā rindā neriktējas kopā, bet vienalga paliek problēma, kā novērst viņu riktēšanos kopā??

Link to comment
Share on other sites

function coloris($value) {
$value = preg_replace('/(\[color=)(.+?)(\])(.+?)(\[\/color\])/', '<span style=\'color:$1\'>$1</span>', $value);
return $value;
}

ā šita?

 

Uzhakos jūsu lapas vienā rāvienā.

 

Es tak iedevu linku!

 

[color=blablabla'<script>alert('xss');</script>]color[/color], jauki, ne?

 

(dotais piemērs nestrādās, bet domu sapratāt, es ceru...)

Edited by briedis
Link to comment
Share on other sites

BB kods jau nav noiets etaps? WYSIWYG FTW

 

Bet par tēmu - http://lv.php.net/manual/en/reference.pcre.pattern.modifiers.php

U (PCRE_UNGREEDY)

This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by ?. It is not compatible with Perl. It can also be set by a (?U) modifier setting within the pattern or by a question mark behind a quantifier (e.g. .*?).

Link to comment
Share on other sites

BB kods jau nav noiets etaps? WYSIWYG FTW

nee noteikti nee ...

ir Ljoti daudz viets kur nelielai eertibai varetu atstat B un i ka arii dazus citus formatesanas riikus,

bet noteikti ne WYSIWYG, kas idejiski ir baazets uz Brauzera editesanas iespejam...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...