From the below preg_match_all() will always return a value of “Array” regardless what I try. To put this into plain code terms, $content will always = “Array”.
I have tested whether it’s getting the right input and it is. There are definetly [test123] and [/test123] custom tags in the php file it’s reading into $buffer which later gets passed into preg_match_all() as $current_line. It should spit out whatever it between these tags.
The bug has got to be in the preg_match_all() right? Thanks in advance.
$rss_source_file = fopen(“$rss_from_file”, “r”) or die(“can’t open file [SOURCE]”);
$rss_write_file = fopen(“$rss_to_file”, “a”) or die(“can’t open file [DESTINATION]”);
Now it’s printing “array(0) { }” which would suggest it’s not even finding the [123test] whatever goes here [/123test] in $current_line
I was thinking this was because [123test] and [/123test] might be on a separate line but I’m reading the file in as one line anyway. The input is good as if I just print the input as I read it then it will simply render the source page inside the current php file (where the script is run).
It’s got to be something with /$start(.*)$end/s in preg_match_all() as I can’t picture it any other way.
You need to make sure that the regex string you pass to preg_match_all is both valid, and what you want. There’s lots of special characters in regular expressions. [ and ] are special. They define a character class. You can’t just allow put anything you want into a regex and expect it to work.
You could make use of preg_quote() to ensure the start and end strings are interpreted literally.
You could also just not use regular expressions. You can easily do the same with a combination of strpos(), strlen(), and substr()
Thanks. So far I’ve taken your first comment onboard and tried the below, sadly this may have been a further bug however the main bug is still in there.
I’m aware about doing it via the strxxx functions but also have come to learn that they’re a lot slower than preg_match_all() which is why I’m trying to stick to it if possible.
I’ve done a search for examples online that also use [whatever here ] custom tags with preg_match_all() and if there is a difference between how I’m passing the strings and how they are then it’s very minute else I like to believe my eyes would spot it by now.