Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6245861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:35:02+00:00 2026-05-24T12:35:02+00:00

My methods parse strings and do stuff with the information contained in the string.

  • 0

My methods parse strings and do stuff with the information contained in the string.
a simple example would be

$string=
"
    user:name,password={$_POST['name']}, {$_POST['password']}(md5); 
    names:name=name;
";
$class->$method($string);

The above would do two insert statements. The first will insert in a table named user the users name and the password encypted in md5.
the second would insert a name in the names table. I’m having setting it up so that characters can be escaped. ie if the users name was p;ez. The string would have p\;ez.
My current method is as follows

    #get position of ;
    $offsetSemi=stripos($s, ";");
    #check if its escaped
    if ($s[$offsetSemi-1]!='\\')
    {
        //not escaped
    }

the problem with the above method is that it will only check the first instance of ;.
the other solution i tried was exploding the string on ;. however this would not work because it exploded on all instances including ones that were escaped. the other thing i tried was an explode with the regular expression below

/[^\\\];/

the prolem with this is that it exploded on the charecter before ; on all the instances that were not escaped. is there a way i can explode a string on all instances of ; that are not preceded by a backslash?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:35:03+00:00Added an answer on May 24, 2026 at 12:35 pm

    Instead of exploding you can parse the string:

    $arr = array();
    $tmp = "";
    
    for ($i = 0; $i < strlen($s); $i++) {
       switch ($s[$i]) {
          case "\\":
             if ($i < strlen($s) - 1) $tmp .= $s[$i++] . $s[$i++];
          break;
          case ";":
             $arr[] = $tmp;
             $tmp = "";
          break;
          default:
             $tmp .= $s[$i];
       }
    }
    
    if (strlen(trim($tmp)) > 0) { // last section
        $arr[] = $tmp;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the fastest way to parse strings in C#? Currently I'm just using string
Is there any way to parse a string in vb.net (like, built in methods),
Jsoup has 2 html parse() methods: parse(String html) - As no base URI is
Aloha I have a method with (pseudo) signature: public static T Parse<T>(string datadictionary) where
I'm implementing a TryParse(string s, Out object result) method. If the parse fails, I
I have the following methods in my simple Custom Parser Class, when I execute
I'm using PHP's DOMDocument to parse and normalize user-submitted HTML using the loadHTML method
in small program I'm writing, I have to parse a line of user input.
I've added some extension methods for strings to make working with some custom enums
I'm developing a simple little search mechanism and I want to allow the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.