Reputation: 21248
The code below picks every line that contains of the word "Homepage:" and extract what's after the semicolon. However what I want instead is that if match on the word "Homepage:" what's on the next line should be grabbed and put in a variable.
How could that be done?
if (preg_match( '/Homepage:/', $text, $match )) {
$pieces = explode(':', $text);
$urls[] = trim($pieces[1]);
}
Example:
Homepage: <--- if match
http://www.fooland.com <--- grab this and put in variable
Upvotes: 0
Views: 63
Reputation: 6852
You can try with explode() in php
$urlResult = explode(':', $url)
echo $urlResult[0];
Upvotes: 1
Reputation: 336408
if (preg_match('/Homepage:.*\n(.*)/', $subject, $regs)) {
$result = $regs[1];
}
Explanation:
Homepage: # Match Homepage:
.* # Match any characters except linebreaks
\n # Match a linebreak
(.*) # Match and capture the contents of the entire line
Upvotes: 2