hello
i would like to split:

www.site.com/page.php?q=SPLITHERE&cat=0&others=1

into

www.site.com/page.php?q=

and

&cat=0&others=1

how can i do that?
i tried with explode, but it didnt work.

please help 🙂

    One way:

    <?php
    $text = "www.site.com/page.php?q=SPLITHERE&cat=0&others=1";
    if(preg_match('/^([^=]+=)[^&]*(&.*)?/', $text, $matches))
    {
       echo $matches[1]."<br />\n".$matches[2];
    }
    else
    {
       user_error("Match failed");
    }

      what if i use:

      <?php
      $text = "www.site.com/page.php?q=SPLITHERE&cat=0&others=1";
      if(preg_match('/*SPLITHERE*/', $text, $matches))
      {
         echo $matches[1]."<br />\n".$matches[2];
      }
      else
      {
         user_error("Match failed");
      } 
      
      ?>
      
      

      but i am not so familiar with regex ..

        Why do you want to do this? You could use [man]parse_url/man under normal circumstances, but this looks strange since you want to parse the URL such that the URL up to part of the query string is in one token and the rest of the query string is in the other token.

          i want it to find the word SPLITHERE and split the url according to that word 🙂

            i want it to find the word SPLITHERE and split the url according to that word

            Why do you want to do that?

              In that case explode should work. explode('SPLITHERE', $url). Either your use of explode was wrong or the description of what you want is wrong 🙂

                kejo wrote:

                how can i do that?
                i tried with explode, but it didnt work.

                please help 🙂

                explode seems not to work with strings containing &

                  '&' has no effect on explode. As Weedpacket says, you must've implemented it incorrectly one way or another - show us what you tried.

                    Write a Reply...