Hi all there I have this string:
All text has PHP_EOL at end of its line.
Some TITLE OF RTMP STREAM
rtmp://slww/best
Some simple text what not required to find
Another not required string line
Used this regex to get rtmp or http links but how can i find its titles?
preg_match_all("/(rtmp:+\S*)|(http:+\S*)/s", $input_lines, $output_array);
That rtmp or html regex works correctly but i need to capture titles of rtmp links too.
Have tried to add ^.*$^
followed by my rtmp http pattern , as ^
its start of line and $
its end of it.
And /s
option for search multiple lines including new line characters.
/^.*$^(rtmp:+\S*)|(http:+\S*)/s
But can not figure it out how can i find its title. Simple what i have tried to archive is to get whole line above my regex or below my regex.
In some cases i need to grab whole line below.
Any thoughts?
You can actually use this regex:
(?m)^(?<TITLE>.*)\R+(?<url>(?:rtmp|http):\S*)
See demo
Note that you are using /s
singleline modifier that forces .
to match newline character but you are not using dot in your pattern. You were looking for mulitline /m
modifier that makes ^
match at the beginning of a line (I used an inline version (?m)
).
I am not using the singleline modifier thus .*
will match just the line before the URL line. The \R
in my regex matches a newline sequence.