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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:41:49+00:00 2026-05-27T06:41:49+00:00

I have a problem here with the php function substr Let’s say I have

  • 0

I have a problem here with the php function substr

Let’s say I have this string coming from an xml file:

$str = '<?xml version="1.0" encoding="utf-8"?><bookstore id="book-1"><languages default="en">';

What I’m trying to do is I’m trying to extract the second tag from that string, the tag

<bookstore id="book-1">

So what I did was this:

First, I got the string starting with the second tag like so:

$newStr = substr($str, strpos($str, '<bookstore '));

My variable $newStr should now be:

$newStr = '<bookstore id="book-1"><languages default="en">';

Then, using that $newStr variable, I tried to get the tag that I wanted (the second tag, which is now the first tag of my $newStr variable) like this:

$wantedTag = substr($newStr, 0, strpos($newStr, '>');

But the problem I’m having is that Nothing is returned (or maybe empty string is returned) when I do this. But if I replace the 0 by 1 like so:

$wantedTag = substr($newStr, 1, strpos($newStr, '>');

I get my second tag but without the initial ‘<‘:

$wantedTag = 'bookstore id="book-1">';

Which makes total sense because the character ‘b’ is at position 1. Why am I not getting anything (or empty string) when I put the start position of the substr function to 0? Any help will be very appreciated.

Please don’t tell me to use any of those XML parsers out there like SimpleXML and stuff, this has nothing to do with XML Parsing, it’s just basic string manipulation techniques.

  • 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-27T06:41:50+00:00Added an answer on May 27, 2026 at 6:41 am

    I take it you’re looking at the result in your browser? The browser will of course interpret any HTML/XML tags, so unless the tag has some content, you won’t see anything of it. The string processing itself seems to work fine, see http://codepad.org/xkU86CJP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with sorting items in table in PHP. Here is what
I have a bit of an architecture problem here. Say I have two tables,
I'm having a bit of a problem here. We have 2 urls let me
Here is the exact problem. I have an autoload function set up with a
I have on my PHP file a function that check if an IP is
I have problem with double links in mydatabase. I have in php file form
Hi i have problem with some things Here is the code function get_char_val(merk) {
I have this code, which uses ob_start php function. Which basically puts the echoed
I have created a file name database.php and here is it's content <?php #Start
I have a problem in passing a value from JS to PHP so that

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.