How to get href value from string
up vote
0
down vote
favorite
I'm trying to get the href from this string, but I can't because it has space inside the link. I try to do it from regex but I'm not an expert in regex. I tried using an example from the internet but I didn't get the value I was after.
<table class="grid border" cellspacing="0" border="0" id="ctl00_ContentBody_grvStudentResult" style="width:100%;border-collapse:collapse;">
<tbody>
<tr>
<th align="left" valign="middle" scope="col">Code</th>
<th align="left" valign="middle" scope="col">Subject</th>
<th align="left" valign="middle" scope="col">Status</th>
<th align="center" valign="middle" scope="col">Score</th>
<th align="center" valign="middle" scope="col">Result Date</th>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PQ
</td>
<td align="left" valign="middle">
<span class="">
1561|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>
</span>
<span class="selected">
</span>
</td>
<td align="left" valign="middle">
<span class="enable">
Competent
</span>
<center style="display: none">
<span disabled="disabled"><input id="ctl00_ContentBody_grvStudentResult_ctl02_chkAP" type="checkbox" name="ctl00$ContentBody$grvStudentResult$ctl02$chkAP" checked="checked" disabled="disabled"><label for="ctl00_ContentBody_grvStudentResult_ctl02_chkAP"> </label></span>
</center>
</td>
<td align="center" valign="middle">
75.00
</td>
<td align="center" valign="middle">
11/11/2018
</td>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PC
</td>
<td align="left" valign="middle">
<span class="">
1559|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559" title="NAN ">
<img alt="" style="display: online" src="../Images/Common/r_.gif" border="0">
[Project Costs] </a>
</span>
<span class="selected">
[progress]
</span>
</td>
<td align="left" valign="middle">
<span class="disable">
</span>
<center style="display: none">
</center>
</td>
<td align="center" valign="middle">
</td>
<td align="center" valign="middle">
</td>
</tr>
</tbody>
php html regex tags
add a comment |
up vote
0
down vote
favorite
I'm trying to get the href from this string, but I can't because it has space inside the link. I try to do it from regex but I'm not an expert in regex. I tried using an example from the internet but I didn't get the value I was after.
<table class="grid border" cellspacing="0" border="0" id="ctl00_ContentBody_grvStudentResult" style="width:100%;border-collapse:collapse;">
<tbody>
<tr>
<th align="left" valign="middle" scope="col">Code</th>
<th align="left" valign="middle" scope="col">Subject</th>
<th align="left" valign="middle" scope="col">Status</th>
<th align="center" valign="middle" scope="col">Score</th>
<th align="center" valign="middle" scope="col">Result Date</th>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PQ
</td>
<td align="left" valign="middle">
<span class="">
1561|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>
</span>
<span class="selected">
</span>
</td>
<td align="left" valign="middle">
<span class="enable">
Competent
</span>
<center style="display: none">
<span disabled="disabled"><input id="ctl00_ContentBody_grvStudentResult_ctl02_chkAP" type="checkbox" name="ctl00$ContentBody$grvStudentResult$ctl02$chkAP" checked="checked" disabled="disabled"><label for="ctl00_ContentBody_grvStudentResult_ctl02_chkAP"> </label></span>
</center>
</td>
<td align="center" valign="middle">
75.00
</td>
<td align="center" valign="middle">
11/11/2018
</td>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PC
</td>
<td align="left" valign="middle">
<span class="">
1559|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559" title="NAN ">
<img alt="" style="display: online" src="../Images/Common/r_.gif" border="0">
[Project Costs] </a>
</span>
<span class="selected">
[progress]
</span>
</td>
<td align="left" valign="middle">
<span class="disable">
</span>
<center style="display: none">
</center>
</td>
<td align="center" valign="middle">
</td>
<td align="center" valign="middle">
</td>
</tr>
</tbody>
php html regex tags
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to get the href from this string, but I can't because it has space inside the link. I try to do it from regex but I'm not an expert in regex. I tried using an example from the internet but I didn't get the value I was after.
<table class="grid border" cellspacing="0" border="0" id="ctl00_ContentBody_grvStudentResult" style="width:100%;border-collapse:collapse;">
<tbody>
<tr>
<th align="left" valign="middle" scope="col">Code</th>
<th align="left" valign="middle" scope="col">Subject</th>
<th align="left" valign="middle" scope="col">Status</th>
<th align="center" valign="middle" scope="col">Score</th>
<th align="center" valign="middle" scope="col">Result Date</th>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PQ
</td>
<td align="left" valign="middle">
<span class="">
1561|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>
</span>
<span class="selected">
</span>
</td>
<td align="left" valign="middle">
<span class="enable">
Competent
</span>
<center style="display: none">
<span disabled="disabled"><input id="ctl00_ContentBody_grvStudentResult_ctl02_chkAP" type="checkbox" name="ctl00$ContentBody$grvStudentResult$ctl02$chkAP" checked="checked" disabled="disabled"><label for="ctl00_ContentBody_grvStudentResult_ctl02_chkAP"> </label></span>
</center>
</td>
<td align="center" valign="middle">
75.00
</td>
<td align="center" valign="middle">
11/11/2018
</td>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PC
</td>
<td align="left" valign="middle">
<span class="">
1559|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559" title="NAN ">
<img alt="" style="display: online" src="../Images/Common/r_.gif" border="0">
[Project Costs] </a>
</span>
<span class="selected">
[progress]
</span>
</td>
<td align="left" valign="middle">
<span class="disable">
</span>
<center style="display: none">
</center>
</td>
<td align="center" valign="middle">
</td>
<td align="center" valign="middle">
</td>
</tr>
</tbody>
php html regex tags
I'm trying to get the href from this string, but I can't because it has space inside the link. I try to do it from regex but I'm not an expert in regex. I tried using an example from the internet but I didn't get the value I was after.
<table class="grid border" cellspacing="0" border="0" id="ctl00_ContentBody_grvStudentResult" style="width:100%;border-collapse:collapse;">
<tbody>
<tr>
<th align="left" valign="middle" scope="col">Code</th>
<th align="left" valign="middle" scope="col">Subject</th>
<th align="left" valign="middle" scope="col">Status</th>
<th align="center" valign="middle" scope="col">Score</th>
<th align="center" valign="middle" scope="col">Result Date</th>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PQ
</td>
<td align="left" valign="middle">
<span class="">
1561|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>
</span>
<span class="selected">
</span>
</td>
<td align="left" valign="middle">
<span class="enable">
Competent
</span>
<center style="display: none">
<span disabled="disabled"><input id="ctl00_ContentBody_grvStudentResult_ctl02_chkAP" type="checkbox" name="ctl00$ContentBody$grvStudentResult$ctl02$chkAP" checked="checked" disabled="disabled"><label for="ctl00_ContentBody_grvStudentResult_ctl02_chkAP"> </label></span>
</center>
</td>
<td align="center" valign="middle">
75.00
</td>
<td align="center" valign="middle">
11/11/2018
</td>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PC
</td>
<td align="left" valign="middle">
<span class="">
1559|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559" title="NAN ">
<img alt="" style="display: online" src="../Images/Common/r_.gif" border="0">
[Project Costs] </a>
</span>
<span class="selected">
[progress]
</span>
</td>
<td align="left" valign="middle">
<span class="disable">
</span>
<center style="display: none">
</center>
</td>
<td align="center" valign="middle">
</td>
<td align="center" valign="middle">
</td>
</tr>
</tbody>
php html regex tags
php html regex tags
edited Nov 17 at 5:45
Nick Parsons
2,3362518
2,3362518
asked Nov 17 at 5:36
Gustavo Filgueiras
5016
5016
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:
$doc = new DOMDocument();
$doc->loadHTML($html);
$anchors = $doc->getElementsByTagName('a');
foreach ($anchors as $a) {
$urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
}
foreach ($urls as $url) {
echo $url;
}
Output
DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
Demo on 3v4l.org
If you have to use regex, this will work for your sample data:
preg_match_all('/href="([^"]+)/', $html, $matches);
print_r($matches[1]);
Output:
Array (
[0] => DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
[1] => DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
)
Demo on 3v4l.org
Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
– Gustavo Filgueiras
Nov 17 at 6:20
@GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
– Nick
Nov 17 at 7:06
add a comment |
up vote
0
down vote
I'm not expert but this work for me
$string ='<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>';
preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );
$urls=array();//array of link
foreach($match as $m){
if (isset($m[0])) {
$url= $m[0];
}}
New contributor
Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thanks for help me brow! But it's dosen't work well =/
– Gustavo Filgueiras
Nov 17 at 5:54
@GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
– Davіd
Nov 17 at 6:01
this regex used on WordPress to get all image from a post.you can use this to get any attribute.
– Mahfuzar Rahman
Nov 17 at 6:01
Yes, sorry! So i need all the links insde the array, like
– Gustavo Filgueiras
Nov 17 at 6:07
$url = $url = "DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" $url = "DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559"
– Gustavo Filgueiras
Nov 17 at 6:08
|
show 1 more comment
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:
$doc = new DOMDocument();
$doc->loadHTML($html);
$anchors = $doc->getElementsByTagName('a');
foreach ($anchors as $a) {
$urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
}
foreach ($urls as $url) {
echo $url;
}
Output
DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
Demo on 3v4l.org
If you have to use regex, this will work for your sample data:
preg_match_all('/href="([^"]+)/', $html, $matches);
print_r($matches[1]);
Output:
Array (
[0] => DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
[1] => DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
)
Demo on 3v4l.org
Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
– Gustavo Filgueiras
Nov 17 at 6:20
@GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
– Nick
Nov 17 at 7:06
add a comment |
up vote
1
down vote
accepted
A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:
$doc = new DOMDocument();
$doc->loadHTML($html);
$anchors = $doc->getElementsByTagName('a');
foreach ($anchors as $a) {
$urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
}
foreach ($urls as $url) {
echo $url;
}
Output
DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
Demo on 3v4l.org
If you have to use regex, this will work for your sample data:
preg_match_all('/href="([^"]+)/', $html, $matches);
print_r($matches[1]);
Output:
Array (
[0] => DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
[1] => DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
)
Demo on 3v4l.org
Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
– Gustavo Filgueiras
Nov 17 at 6:20
@GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
– Nick
Nov 17 at 7:06
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:
$doc = new DOMDocument();
$doc->loadHTML($html);
$anchors = $doc->getElementsByTagName('a');
foreach ($anchors as $a) {
$urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
}
foreach ($urls as $url) {
echo $url;
}
Output
DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
Demo on 3v4l.org
If you have to use regex, this will work for your sample data:
preg_match_all('/href="([^"]+)/', $html, $matches);
print_r($matches[1]);
Output:
Array (
[0] => DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
[1] => DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
)
Demo on 3v4l.org
A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:
$doc = new DOMDocument();
$doc->loadHTML($html);
$anchors = $doc->getElementsByTagName('a');
foreach ($anchors as $a) {
$urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
}
foreach ($urls as $url) {
echo $url;
}
Output
DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
Demo on 3v4l.org
If you have to use regex, this will work for your sample data:
preg_match_all('/href="([^"]+)/', $html, $matches);
print_r($matches[1]);
Output:
Array (
[0] => DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561
[1] => DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559
)
Demo on 3v4l.org
edited Nov 17 at 7:05
answered Nov 17 at 6:16
Nick
19k41433
19k41433
Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
– Gustavo Filgueiras
Nov 17 at 6:20
@GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
– Nick
Nov 17 at 7:06
add a comment |
Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
– Gustavo Filgueiras
Nov 17 at 6:20
@GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
– Nick
Nov 17 at 7:06
Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
– Gustavo Filgueiras
Nov 17 at 6:20
Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
– Gustavo Filgueiras
Nov 17 at 6:20
@GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
– Nick
Nov 17 at 7:06
@GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
– Nick
Nov 17 at 7:06
add a comment |
up vote
0
down vote
I'm not expert but this work for me
$string ='<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>';
preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );
$urls=array();//array of link
foreach($match as $m){
if (isset($m[0])) {
$url= $m[0];
}}
New contributor
Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thanks for help me brow! But it's dosen't work well =/
– Gustavo Filgueiras
Nov 17 at 5:54
@GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
– Davіd
Nov 17 at 6:01
this regex used on WordPress to get all image from a post.you can use this to get any attribute.
– Mahfuzar Rahman
Nov 17 at 6:01
Yes, sorry! So i need all the links insde the array, like
– Gustavo Filgueiras
Nov 17 at 6:07
$url = $url = "DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" $url = "DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559"
– Gustavo Filgueiras
Nov 17 at 6:08
|
show 1 more comment
up vote
0
down vote
I'm not expert but this work for me
$string ='<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>';
preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );
$urls=array();//array of link
foreach($match as $m){
if (isset($m[0])) {
$url= $m[0];
}}
New contributor
Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thanks for help me brow! But it's dosen't work well =/
– Gustavo Filgueiras
Nov 17 at 5:54
@GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
– Davіd
Nov 17 at 6:01
this regex used on WordPress to get all image from a post.you can use this to get any attribute.
– Mahfuzar Rahman
Nov 17 at 6:01
Yes, sorry! So i need all the links insde the array, like
– Gustavo Filgueiras
Nov 17 at 6:07
$url = $url = "DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" $url = "DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559"
– Gustavo Filgueiras
Nov 17 at 6:08
|
show 1 more comment
up vote
0
down vote
up vote
0
down vote
I'm not expert but this work for me
$string ='<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>';
preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );
$urls=array();//array of link
foreach($match as $m){
if (isset($m[0])) {
$url= $m[0];
}}
New contributor
Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm not expert but this work for me
$string ='<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>';
preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );
$urls=array();//array of link
foreach($match as $m){
if (isset($m[0])) {
$url= $m[0];
}}
New contributor
Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Nov 17 at 5:48
Mahfuzar Rahman
667
667
New contributor
Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thanks for help me brow! But it's dosen't work well =/
– Gustavo Filgueiras
Nov 17 at 5:54
@GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
– Davіd
Nov 17 at 6:01
this regex used on WordPress to get all image from a post.you can use this to get any attribute.
– Mahfuzar Rahman
Nov 17 at 6:01
Yes, sorry! So i need all the links insde the array, like
– Gustavo Filgueiras
Nov 17 at 6:07
$url = $url = "DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" $url = "DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559"
– Gustavo Filgueiras
Nov 17 at 6:08
|
show 1 more comment
Thanks for help me brow! But it's dosen't work well =/
– Gustavo Filgueiras
Nov 17 at 5:54
@GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
– Davіd
Nov 17 at 6:01
this regex used on WordPress to get all image from a post.you can use this to get any attribute.
– Mahfuzar Rahman
Nov 17 at 6:01
Yes, sorry! So i need all the links insde the array, like
– Gustavo Filgueiras
Nov 17 at 6:07
$url = $url = "DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" $url = "DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559"
– Gustavo Filgueiras
Nov 17 at 6:08
Thanks for help me brow! But it's dosen't work well =/
– Gustavo Filgueiras
Nov 17 at 5:54
Thanks for help me brow! But it's dosen't work well =/
– Gustavo Filgueiras
Nov 17 at 5:54
@GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
– Davіd
Nov 17 at 6:01
@GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
– Davіd
Nov 17 at 6:01
this regex used on WordPress to get all image from a post.you can use this to get any attribute.
– Mahfuzar Rahman
Nov 17 at 6:01
this regex used on WordPress to get all image from a post.you can use this to get any attribute.
– Mahfuzar Rahman
Nov 17 at 6:01
Yes, sorry! So i need all the links insde the array, like
– Gustavo Filgueiras
Nov 17 at 6:07
Yes, sorry! So i need all the links insde the array, like
– Gustavo Filgueiras
Nov 17 at 6:07
$url = $url = "DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" $url = "DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559"
– Gustavo Filgueiras
Nov 17 at 6:08
$url = $url = "DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561" $url = "DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559"
– Gustavo Filgueiras
Nov 17 at 6:08
|
show 1 more comment
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348556%2fhow-to-get-href-value-from-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown