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 8759681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:52:00+00:00 2026-06-13T14:52:00+00:00

I am trying to extract bits of a string. The string looks like this:

  • 0

I am trying to extract bits of a string.

The string looks like this:

$rowstr = "8:12-bk-16430|8:2012-bk-16430|1080751|7|||||10/30/2012|1/30/2012|||bk|||PINELLAS-FL|Tampa|Paid...

I get the first field just fine using this:

$pos1 = strpos($rowstr, "|") +1; //begining of field case number
$pos2 = strpos($rowstr, "|", $pos1 + 1); //end of field case number
$len1 = $pos2 - $pos1;  //string length
$field['case_num'][$i] = substr($rowstr,$pos1,$len1); // casenumber extracted

But when I try to extract the second field (should be 1080751)

$pos3 = strpos($rowstr, "|", $pos2); //end of field 
$pos4 = strpos($rowstr, "|", $pos3 + 1); //end of field
$len2 = $pos3 - $pos4;  //string length
$field['field2'][$i] = substr($rowstr,$pos3,$len2); // field 2 extracted

The result is a very long string that starts with |1080751|7|||||10/30/2012|10...

If $pos3 returns 16 and $pos4 returns 24 then why am I getting a result so much longer than 8 characters? Is PHP not counting special charters for some reason? How can I fix this?

  • 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-06-13T14:52:01+00:00Added an answer on June 13, 2026 at 2:52 pm

    Try

    // Added + 1 here
    $pos3 = strpos($rowstr, "|", $pos2) + 1; //end of field
    $pos4 = strpos($rowstr, "|", $pos3 + 1); //end of field
    // swapped $pos3 and $pos4 here
    $len2 = $pos4 - $pos3;  //string length
    $field['field2'][$i] = substr($rowstr,$pos3,$len2); // field 2 extracted
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to extract strings that are wrapped in double brackets. For example [[this is
I am trying to extract the page name from a complex url. This post
I am trying to extract a date from a string variable and was hoping
I'm trying to extract the domain name from a string in C#. You don't
I am trying to extract the mp3 header from a file. This is different
I am trying extract some information from the below given string >>> st =
I am trying to extract the bits from a float without invoking undefined behavior.
I have a boost dynamic_bitset that I am trying to extract the set bits
Im trying to extract some fields from the output at the end of this
hi i'm trying to extract values from this tagged file here is the file

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.