|
-
Jul 31st, 2002, 12:43 PM
#1
Thread Starter
Fanatic Member
Warning: Unknown modifier ...
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:
PHP Code:
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
Last edited by cpradio; Jul 31st, 2002 at 04:47 PM.
-
Jul 31st, 2002, 04:44 PM
#2
Frenzied Member
first mysql_numrows is deprecated and should not be used. come on standards man 
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?
-
Jul 31st, 2002, 04:48 PM
#3
Thread Starter
Fanatic Member
What is mysql_numrows() equivalent function? and I edited the above to display line 505
-
Jul 31st, 2002, 04:50 PM
#4
Frenzied Member
ok the equivalent function to mysql_numrows is hold yourself now
mysql_num_rows() 
so echo the $text before you return it so you can see what it is trying to match.
-
Jul 31st, 2002, 05:03 PM
#5
Thread Starter
Fanatic Member
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
-
Jul 31st, 2002, 05:28 PM
#6
Frenzied Member
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
PHP Code:
for ($i=0;$i<sizeof($abArray);$i++) {
// line 505 below
$text = preg_replace("/".preg_quote($abArray[$i])."/",$$htmlArray[$i],$text);
echo $text;
}
return $text;
-
Jul 31st, 2002, 05:31 PM
#7
Thread Starter
Fanatic Member
PHP Code:
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
-
Jul 31st, 2002, 05:41 PM
#8
Frenzied Member
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"
-
Aug 1st, 2002, 10:00 AM
#9
Thread Starter
Fanatic Member
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
-
Aug 1st, 2002, 10:09 AM
#10
Frenzied Member
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}
-
Aug 1st, 2002, 10:48 AM
#11
Frenzied Member
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
-
Aug 1st, 2002, 10:57 AM
#12
Thread Starter
Fanatic Member
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.
-
Aug 1st, 2002, 11:41 AM
#13
Frenzied Member
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 Code:
<?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.
-
Aug 1st, 2002, 12:02 PM
#14
Thread Starter
Fanatic Member
okay, now the tough part, how can I make that regexp on the fly without knowing what the user had typed in?
-
Aug 1st, 2002, 12:16 PM
#15
Thread Starter
Fanatic Member
Okay, what is wrong with this:
Results: http://cpradio.net/advBlogger/user/display.php?cid=18
PHP Code:
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
Last edited by cpradio; Aug 1st, 2002 at 12:36 PM.
-
Aug 1st, 2002, 12:53 PM
#16
Thread Starter
Fanatic Member
WOHOO! I got it working. 
What the code looks like now:
PHP Code:
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;
}
}
-
Aug 1st, 2002, 01:32 PM
#17
Frenzied Member
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.
-
Aug 1st, 2002, 01:39 PM
#18
Thread Starter
Fanatic Member
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?
-
Aug 1st, 2002, 02:30 PM
#19
Frenzied Member
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.
-
Aug 1st, 2002, 02:41 PM
#20
Thread Starter
Fanatic Member
well, it can't do that, can it?
For example say I have this:
abTag: [test={option}]{param}[/test]
htmlTag: Param = {param} and Option = {option}
This is the display I get when I enter [test="Part 1"]"Part 2"[/test]:
Param = "Part 1" and Option = "Part 2"
It's backwards
-
Aug 1st, 2002, 03:06 PM
#21
Frenzied Member
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.
PHP Code:
<?
$code = '[ color=anycolor]any text[/color ]';
$search = array("'[color'",
"']'",
"'[/color'");
$replace = array("<font color",
">",
"</font");
$text = preg_replace ($search, $replace, $code);
echo $text;
?>
-
Aug 1st, 2002, 03:09 PM
#22
Thread Starter
Fanatic Member
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
-
Aug 1st, 2002, 03:25 PM
#23
Frenzied Member
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.
-
Aug 1st, 2002, 04:06 PM
#24
Thread Starter
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|