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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:08:21+00:00 2026-06-05T08:08:21+00:00

This is sort of a rookie question, but… I’m calling a function in another

  • 0

This is sort of a rookie question, but…

I’m calling a function in another php file that uses preg_match to get a string. I then want to use substr to get a specific part of that string, however it doesn’t output any of the characters in the string. When I replace the variable from the preg_match function, I get the right output.

Here is the basic code:

$title = $stream["song1"]; // From a preg_match in an external php file
echo $title; // Correctly prints the song name, in this case "mySong"
echo substr($title, 0, 1);  // Outputs a "<" symbol (why??)

If I run the same three lines above, but hard code the song title:

$title = "mySong";
echo $title; // Correctly prints the song name, in this case "mySong"
echo substr($title, 0, 1);  // Outputs a "m" symbol (correct)

Also, when I check the type of variable $title is, it returns “string”. I’m sure I’m doing something really stupid… can anyone help?

  • 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-05T08:08:25+00:00Added an answer on June 5, 2026 at 8:08 am

    It seems $title contains html tags, thus the first character will be the <.

    Use htmlentities() to echo the full output and then you should be able to see which part of the string you’re actually looking for.

    echo htmlentities($title);
    

    Alternatively, you can simply remove all html tags from the string using strip_tags():

    $title = strip_tags($title);
    echo substr($title, 0, 1); // should work
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this sort of question has been asked before , but I still
I don't normally make this sort of question / answer, but figured I'd do
I realized this sort of question is scattered all over the Internet, but nothing
I know this sort of question has been banded about before but I've not
This question is probably for MySQL experts and admins that have done this sort
I have this sort of C function -- that is being called a zillion
I have answered this sort of in a previous question but now I have
I asked this sort of question before ( Application fails to dynamically _re_load JavaScript
I know this sort of code is not best practice, but nevertheless in certain
The UNIX sort command can sort a very large file like this: sort large_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.