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?
It seems
$titlecontains 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.
Alternatively, you can simply remove all html tags from the string using strip_tags():