Click to See Complete Forum and Search --> : Warning: Unknown modifier ...
cpradio
Jul 31st, 2002, 12:43 PM
I have been working on a preg_replace function that is used to create and manipulate customized code while turning it into html code. Well anyways, I am getting the following errors:
http://cpradio.net/advBlogger/user/display.php?cid=18
If anyone thinks they know the answer or thinks they can retrieve the answer, send me a pm or post such here, and I will pm you a link to the admin area where you will be able to write new "code" tags and see how it is supposed to operate.
Here is the function that is computing those errors:
function ParseCode($text = "Invalid use of Function",$abCode = 1) {
if ($abCode) {
$abArray = array();
$htmlArray = array();
$query = mysql_query("select * from abCode");
for($i=0;$i<mysql_numrows($query);$i++) {
$abTag = mysql_result($query,$i,"abTag");
$htmlTag = mysql_result($query,$i,"htmlTag");
$option = 1;
while (preg_match("/\{option\}/is",$abTag)) {
$abTag = preg_replace("/\{option\}/is","(.*?)",$abTag,1);
$option++;
}
while (preg_match("/\{param\}/is",$abTag)) {
$abTag = preg_replace("/\{param\}/is","(.*?)",$abTag,1);
$option++;
}
$abArray[$i] = $abTag;
$replace = 1;
while (preg_match("/\{option\}/is",$htmlTag)) {
$htmlTag = preg_replace("/\{option\}/is",$$replace,$htmlTag,1);
$replace++;
}
while (preg_match("/\{param\}/is",$htmlTag)) {
$htmlTag = preg_replace("/\{param\}/is",$$replace,$htmlTag,1);
$replace++;
}
$htmlArray[$i] = $htmlTag;
}
for ($i=0;$i<sizeof($abArray);$i++) {
// line 505 below
$text = preg_replace("/".preg_quote($abArray[$i])."/",$$htmlArray[$i],$text);
}
return $text;
}
}
-Matt
phpman
Jul 31st, 2002, 04:44 PM
first mysql_numrows is deprecated and should not be used. come on standards man :D
then I would suggest to echo the results of every preg_match to find out where exactly the error is coming from. I just had this error so I know what to kind of look for. what line is 505?
cpradio
Jul 31st, 2002, 04:48 PM
What is mysql_numrows() equivalent function? and I edited the above to display line 505
phpman
Jul 31st, 2002, 04:50 PM
ok the equivalent function to mysql_numrows is hold yourself now
mysql_num_rows() :p
so echo the $text before you return it so you can see what it is trying to match.
cpradio
Jul 31st, 2002, 05:03 PM
okay...this is really weird!
http://cpradio.net/advBlogger/user/display.php?cid=18
Now I know it's working b/c it is causing this weird problem. It is replacing the words url in [url] to \\1 or something like that along with the rest of the custom codes.
And what the HELL is with placing an underline between num and rows!! Why make something more bytes than what it used to be?
-Matt
phpman
Jul 31st, 2002, 05:28 PM
so what is it exactly replacing. I know it is the vbcode like here but in the line you said it is replacing everything with \\1 and such. try taking off the last parameter in the preg_replace. and are you echoing the text like this
for ($i=0;$i<sizeof($abArray);$i++) {
// line 505 below
$text = preg_replace("/".preg_quote($abArray[$i])."/",$$htmlArray[$i],$text);
echo $text;
}
return $text;
cpradio
Jul 31st, 2002, 05:31 PM
function ParseCode($text = "Invalid use of Function",$abCode = 1) {
if ($abCode) {
$abArray = array();
$htmlArray = array();
$query = mysql_query("select * from abCode");
for($i=0;$i<mysql_numrows($query);$i++) {
$abTag = mysql_result($query,$i,"abTag");
$htmlTag = mysql_result($query,$i,"htmlTag");
$option = 1;
while (preg_match("/\{option\}/is",$abTag)) {
$abTag = preg_replace("/\{option\}/is","(.*?)",$abTag,1);
$option++;
}
while (preg_match("/\{param\}/is",$abTag)) {
$abTag = preg_replace("/\{param\}/is","(.*?)",$abTag,1);
$option++;
}
$abArray[$i] = $abTag;
$replace = 1;
while (preg_match("/\{option\}/is",$htmlTag)) {
$htmlTag = preg_replace("/\{option\}/is","\\\\".$replace,$htmlTag,1);
$replace++;
}
while (preg_match("/\{param\}/is",$htmlTag)) {
$htmlTag = preg_replace("/\{param\}/is","\\\\".$replace,$htmlTag,1);
$replace++;
}
$htmlArray[$i] = $htmlTag;
}
for ($i=0;$i<sizeof($abArray);$i++) {
echo "$text<br />";
// line 505 below
$text = preg_replace("/".$abArray[$i]."/",$$htmlArray[$i],$text);
echo "$abArray[$i]<br />$htmlArray[$i]<br />$text<br />";
}
return $text;
}
}
That is what I am using right now.
What do you mean by drop the last parameter?
BTW, in my actuall code there are 4 slashes, VBulletin only shows 2
phpman
Jul 31st, 2002, 05:41 PM
the last parameter.....
preg_replace("/{option}/is","\\".$replace,$htmlTag,1);
take the 1 off
so if you are echoing the text variable then where is it? I don't see "Invalid use of Function"
cpradio
Aug 1st, 2002, 10:00 AM
I can't take the 1 off. I need that so it only replaces 1 set at a time.
Invalid Use of Function will not be shown as, it is running text stored in a database, which are these two phrases:
Just goofin around today... beta testing... la dee da. :)
[b]demo[/b]
-Matt
phpman
Aug 1st, 2002, 10:09 AM
ok so then it loops through the function 2 times?
but you have
function ParseCode($text = "Invalid use of Function",$abCode = 1)
and then you say the text is coming from the database? pm me the info that is stored in the DB so I can replicate it if you don't mind. and some codeso I can use that function. actually what is your regular expressions that you are using, beside {param}
phpman
Aug 1st, 2002, 10:48 AM
ok I kind a see how it works. so what is the regexp code?
I would have replied in the pm but it seems it is real buggy and it doesn't show the reply buttons listed. these forums are falling apart :)
how did you know it was me? :) man I just can't hide lol
cpradio
Aug 1st, 2002, 10:57 AM
regexp code? Are you talking about what is in the abCode area of the PM I sent you?
Or the above code I am using? Cause those are the only two things I have that run this operation.
phpman
Aug 1st, 2002, 11:41 AM
well somewhere you should have the regexp code to parse the [url] and stuff. that is why it is dying.
so you have this
[ url={option}]{param}[/url ]
and the param and option is replaced with what the user typed in? so let me create a regexp that will parse what you are trying to and replace it. am I correct?
so something like this
<?php
$str = '[ color=blue]any [text][/color ]';
$ptn = '/(\[)(color)(=)(.*)(\])(.*)(\[\/color\])/siU';
$replace = "<font color=\"\\4\"> \\6</font>";
print preg_replace($ptn, $replace, $str);
?>
see how I look for the [ and tuff in it? you should get the idea, same principal anyway.
cpradio
Aug 1st, 2002, 12:02 PM
okay, now the tough part, how can I make that regexp on the fly without knowing what the user had typed in?
cpradio
Aug 1st, 2002, 12:16 PM
Okay, what is wrong with this:
Results: http://cpradio.net/advBlogger/user/display.php?cid=18
function ParseCode($text = "Invalid use of Function",$abCode = 1) {
if ($abCode) {
$abArray = array();
$htmlArray = array();
$query = mysql_query("select * from abCode");
for($i=0;$i<mysql_numrows($query);$i++) {
$abTag = mysql_result($query,$i,"abTag");
$htmlTag = mysql_result($query,$i,"htmlTag");
$option = 1;
while (preg_match("/\\{(option|param)\\}/is",$abTag)) {
$abTag = preg_replace("/\\{(option|param)\\}/is","(.*?)",$abTag,1);
$option++;
}
$abArray[$i] = $abTag;
$replace = 1;
while (preg_match("/\\{(option|param)\\}/is",$htmlTag)) {
$htmlTag = preg_replace("/\\{(option|param)\\}/is","\\\\".$replace,$htmlTag,1);
$replace++;
}
$htmlArray[$i] = $htmlTag;
}
for ($i=0;$i<sizeof($abArray);$i++) {
echo "$text<br />";
$text = preg_replace("/".$abArray[$i]."/",$htmlArray[$i],$text);
echo "$abArray[$i]<br />$htmlArray[$i]<br />$text<br />";
}
return $text;
}
}
Changed Code
cpradio
Aug 1st, 2002, 12:53 PM
WOHOO! I got it working. :D
What the code looks like now:
function ParseCode($text = "Invalid use of Function",$abCode = 1) {
if ($abCode) {
$abArray = array();
$htmlArray = array();
$query = mysql_query("select * from abCode");
for($i=0;$i<mysql_numrows($query);$i++) {
$abTag = mysql_result($query,$i,"abTag");
$htmlTag = mysql_result($query,$i,"htmlTag");
$option = 1;
while (preg_match("/\\{(option|param)\\}/is",$abTag)) {
$abTag = preg_replace("/\\{(option|param)\\}/is","(.*?)",$abTag,1);
$option++;
}
$abArray[$i] = $abTag;
$replace = 1;
while (preg_match("/\\{(option|param)\\}/is",$htmlTag)) {
$htmlTag = preg_replace("/\\{(option|param)\\}/is","\\\\\\\\".$replace,$htmlTag,1);
$replace++;
}
$htmlArray[$i] = $htmlTag;
}
for ($i=0;$i<sizeof($abArray);$i++) {
$abArray[$i] = str_replace("[","\\[",$abArray[$i]);
$abArray[$i] = str_replace("]","\\]",$abArray[$i]);
$abArray[$i] = str_replace("/","\\/",$abArray[$i]);
$text = preg_replace("/".$abArray[$i]."/",$htmlArray[$i],$text);
}
return $text;
}
}
phpman
Aug 1st, 2002, 01:32 PM
Originally posted by cpradio
okay, now the tough part, how can I make that regexp on the fly without knowing what the user had typed in?
easy you can just make an array it looks at and if they match they gt replaced. easy thing to do. but glad you got it working.
cpradio
Aug 1st, 2002, 01:39 PM
Originally posted by phpman
easy you can just make an array it looks at and if they match they gt replaced. easy thing to do. but glad you got it working.
Well, I have one more problem. Say you have the following in your blog/text:
[color=#FF0000]text[/color]
Say one of the abCode Tags are setup as so:
abTag: [color={option}]{param}[/color]
Now let's say you for some reason wanted the htmlTag to print out the {param} value before it printed out the {option} value. With my code it just takes the {option} value in abTag and places it in the {param} value of the htmlTag. I need to ensure it is placed properly, how can I do that?
phpman
Aug 1st, 2002, 02:30 PM
it should get replaced properly. if it finds option then it will do that one, if it doesn't find option then it will do the param. so you shouldn't have to worry abou it.
cpradio
Aug 1st, 2002, 02:41 PM
well, it can't do that, can it?
For example say I have this:
abTag: {param}
htmlTag: Param = {param} and Option = {option}
This is the display I get when I enter "Part 2":
Param = "Part 1" and Option = "Part 2"
It's backwards :(
phpman
Aug 1st, 2002, 03:06 PM
well tha tis wierd and must be teh way you coded it because this line
preg_match("/\{(option|param)\}/is",$htmlTag))
what this says is if option then replace if no option then use param. so I don't see how it changes places.
this is the array I was taling about.
<?
$code = '[ color=anycolor]any text[/color ]';
$search = array("'[color'",
"']'",
"'[/color'");
$replace = array("<font color",
">",
"</font");
$text = preg_replace ($search, $replace, $code);
echo $text;
?>
cpradio
Aug 1st, 2002, 03:09 PM
see, the problem with that array thing, is I have no idea what the user will type into the fields when they make the custom code which is stored in a database.
I have no idea how many {option}'s an d{param}'s they will use nor, the order they will use them in.
I guess I could have two functions. One that handles the {option} and the other handles the {param}, but that seems redundant
phpman
Aug 1st, 2002, 03:25 PM
oh yeah I forgot you are having them make their own tags.
well I think you will be asking for a lot of code that will be usless - in time.
say you have 30,000 members and each one made their own tag, do you realize that that is a lot of code to remember.
so what about that code that I pm'ed you a while ago? it tells exactly what code you typed in.
cpradio
Aug 1st, 2002, 04:06 PM
this is for people who use my script only admins will have access to create custom code on their own site, kinda like how vB functions.
I looked at vB's code and found it too confusing. That is why I went my own path.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.