Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by peps03
at 2024-07-04 03:28:08
Point:500 Replies:8 POST_ID:828935USER_ID:11599
Topic:
PHP Scripting Language;Regular Expressions;Perl Programming Language
Hi,
I'm searching for a way to get all complete <a> tags from a string.
So: < a href="example.com" target="_blank" rel="nofollow">Test</a>
How could i do this?
Thanks!
I'm searching for a way to get all complete <a> tags from a string.
So: < a href="example.com" target="_blank" rel="nofollow">Test</a>
How could i do this?
Thanks!
Expert: duncanb7 replied at 2024-07-04 05:08:20
Thanks for your points
Have a nice day
Duncan
Have a nice day
Duncan
Author: peps03 replied at 2024-07-04 05:03:04
Thanks!!
Got it! Exactly what i was looking for :)
Got it! Exactly what i was looking for :)
Expert: Ray Paseur replied at 2024-07-04 04:44:32
You can do this with regular expressions or with a state engine. The choice will depend on the format of the input data. Please post your test data (or a link to your test data) and show us exactly what you would want the program to get out of the input data. Once we see the SSCCE we can show you tested-and-working scripts that will find the links.
Assisted Solution
Expert: duncanb7 replied at 2024-07-04 04:10:36
166 points EXCELLENT
It is working at my side to strip out all <a> tags including complete inside and outside tag
<?php$string="<a href=''>test</a><br>test</br><a href=''>test2</a><br><br>";$result=preg_match_all('~<as+.*?</a>~is',$string,$anchors);print_r($anchors);echo "--------------------";echo ($anchors[0][0]);echo "";echo ($anchors[0][1]);echo "";echo "---------------------";$cnt=count($anchors[0]);for ($i=0;$i<$cnt;$i++){echo $anchors[0][$i]."";} 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:
Expert: duncanb7 replied at 2024-07-04 04:07:06
The code is printing all <a> tags string including inside of <a> such as href=...
Duncan
Duncan
Accepted Solution
Expert: duncanb7 replied at 2024-07-04 04:05:06
167 points EXCELLENT
There is different ways to print output if the output is what you need
print_r($anchors[0]);
or
echo $anchors[0][0];
echo $anchors[0][1];
or
$cnt=count($anchors[0]);
for ($i=0;$i<$cnt;$i++){
echo $anchors[0][$i]."";
}
print_r($anchors[0]);
or
echo $anchors[0][0];
echo $anchors[0][1];
or
$cnt=count($anchors[0]);
for ($i=0;$i<$cnt;$i++){
echo $anchors[0][$i]."";
}
Author: peps03 replied at 2024-07-04 04:01:21
Thanks for your reply.
This code only prints the anchor.
I would like the whole link printed:
Output: < a href="example.com" target="_blank" rel="nofollow">Test</a>
This code only prints the anchor.
I would like the whole link printed:
Output: < a href="example.com" target="_blank" rel="nofollow">Test</a>
Assisted Solution
Expert: duncanb7 replied at 2024-07-04 03:49:43
167 points EXCELLENT
Is it what you need for the following code to get all complete <a> tags from a string?
Please replace your input string to $string variable in the code
and the result is at array of $anchors
In other way, you can consider to use strip_tags() in php at
http://www.php.net/manual/en/function.strip-tags.php
If you write down input string and output string you want, that will help others to understand your question completely .
Duncan
Please replace your input string to $string variable in the code
and the result is at array of $anchors
In other way, you can consider to use strip_tags() in php at
http://www.php.net/manual/en/function.strip-tags.php
If you write down input string and output string you want, that will help others to understand your question completely .
Duncan
<?php//Example to strip all a tag string$string="<a href=''>test</a><br>test</br><a href=''>test2</a><br><br>";$result=preg_match_all('~<as+.*?</a>~is',$string,$anchors);print_r($anchors[0]);?> 1:2:3:4:5:6:7: