• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with [coder] tags in article

#1
[eluser]double_d[/eluser]
Hi all,

Thing I want to do is to use
Code:
highlight_code
on text between [coder][/coder] tags.

got kind of a problem with preg_match (that was first thing I found to use...)

I didn't find any CI function that would do what I want (I was looking in text helper).


here is the code...

Code:
$str = 'bla bla bla [coder]#!/bin/bash
cat banner.txt
OPTIONS="SERVER1 SERVER2 SERVER3 QUIT"
select opt in $OPTIONS; do
if [ "$opt" = "QUIT" ]; then
echo Bye...
exit
elif [ "$opt" = "SERVER1" ]; then
ssh user@server1_IP
elif [ "$opt" = "SERVER2" ]; then
ssh user@server2_IP
elif [ "$opt" = "SERVER3" ]; then
ssh user@server3_IP
else
clear
echo "error, no such option"
fi
done[/coder] bla bla bla';

$ref = preg_match("/[coder](.*)[\/coder]/", $str, $matches);

$string = highlight_code($matches[1]);

echo $string;

but output on page is only oder]#!/bin

Did I overlook some CI function or smthn, and if there isn't any what is wrong with my code...

tnx in advance

#2
[eluser]Vlad0[/eluser]
http://codeigniter.com/wiki/Another_BBCode_Helper/

#3
[eluser]GSV Sleeper Service[/eluser]
you need to escape the square brackets too, also "." will not match newlines.

#4
[eluser]double_d[/eluser]
[quote author="Vlad0" date="1228165096"]http://codeigniter.com/wiki/Another_BBCode_Helper/[/quote]

@Vlad (cepes Smile )

do I really need to integrate complete helper in CI so I could just use one tag



escaping square brackets gives me error when returning data from array ...


will try to get the solution from that BB helper...

#5
[eluser]narkaT[/eluser]
[quote author="double_d" date="1228165872"]escaping square brackets gives me error when returning data from array ...[/quote]

because no matches are found.
you should check if the expression matched anything before working with the "result":

Code:
if ( preg_match(/*....*/) ) {
    // your code
}

your expression won't match anything containing newlines because
the appropriate pattern modifier is missing Smile

#6
[eluser]double_d[/eluser]
Code:
$ref = preg_match("/\[coder](.*)\[\/coder]/sim", $str, $matches);

works as a charm Smile tnx allot


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.