Results 1 to 24 of 24

Thread: Warning: Unknown modifier ...

  1. #1

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616

    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.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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?

  3. #3

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    What is mysql_numrows() equivalent function? and I edited the above to display line 505
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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.

  5. #5

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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

  7. #7

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  8. #8
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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"

  9. #9

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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.
    [&#098;]demo[/b]

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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}

  11. #11
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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

  12. #12

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  13. #13
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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.

  14. #14

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    okay, now the tough part, how can I make that regexp on the fly without knowing what the user had typed in?
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  15. #15

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  16. #16

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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;
        }
      } 
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  17. #17
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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.

  18. #18

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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:
    [c&#111;lor=#FF0000]text[/c&#111;lor]

    Say one of the abCode Tags are setup as so:
    abTag: [c&#111;lor={option}]{param}[/c&#111;lor]

    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?
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  19. #19
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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.

  20. #20

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  21. #21
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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;
    ?>

  22. #22

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  23. #23
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    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.

  24. #24

    Thread Starter
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width