/    Sign up×
Community /Pin to ProfileBookmark

parse_link AND Not parse_url

Folks,

You know how to parse_url like so:

print_r()

[code]
<?php
$url1 = ‘https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29’;
print_r(parse_url($url1)); echo ‘<br>’;
echo __LINE__; echo ‘<br>’; echo ‘<br>’;
?>
[/code]

var_dump()

[code]
<?php
$url2 = ‘https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29’;
var_dump(parse_url($url2)); echo ‘<br>’;
echo __LINE__; echo ‘<br>’; echo ‘<br>’;
?>
[/code]

But have you tried parsing a link ? Such as this:
**<a href=”https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29″>Link1</a>**

Try and see what results you get!
These ain’t working for me:

print_r()

[code]
<?php
$link1 = ‘<a href=”https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29″>Link1</a>’;
print_r(parse_url($link1)); echo ‘<br>’;
echo __LINE__; echo ‘<br>’; echo ‘<br>’;
?>
[/code]

var_dump()

[code]
<?php
$link2 = ‘<a href=”https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29″>Link2</a>’;
var_dump(parse_url($link2)); echo ‘<br>’;
echo __LINE__; echo ‘<br>’; echo ‘<br>’;
?>
[/code]

**Using htmlentities():**

print_r()

[code]
<?php
$link1 = ‘<a href=”https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29″>Link1</a>’;
print_r(parse_url(htmlentities($link1))); echo ‘<br>’;
echo __LINE__; echo ‘<br>’; echo ‘<br>’;
?>
[/code]

var_dump()

[code]
$link2 = ‘<a href=”https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29″>Link2</a>’;
var_dump(parse_url(htmlentities($link2))); echo ‘<br>’;
echo __LINE__; echo ‘<br>’; echo ‘<br>’;
[/code]

I see no parse_link() function in php. And so, let’s custom build one. I don;t know how to start so how about you make the first attempt ?

NOTE: I am trying to grab the url from the link and then parse the url.

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@developer_webauthorJun 05.2021 — Folks,

These ain't working. Stripping tags:

1st Attempt with print_r().

print_r()
<i>
</i>&lt;?php
$link5 = '&lt;a href="https://localhost/Templates/Grab_Url.php?search=keyword&amp;tbl=links&amp;col=keyword&amp;max=1&amp;page=29"&gt;Link1&lt;/a&gt;';
print_r(parse_url(strip_tags($link5))); echo '&lt;br&gt;';
echo __LINE__; echo '&lt;br&gt;'; echo '&lt;br&gt;';
?&gt;


It's not echoing something like this:

**Array ( [scheme] => https [host] => localhost [path] => /Templates/Grab_Url.php [query] => search=keyword&tbl=links&col=keyword&max=1&page=29 )

34**


Instead, I see crap like this:

**Array ( [path] => Link1 )**

2nd Attempt with var_dump().

var_dump()
<i>
</i>&lt;?php
$link6 = '&lt;a href="https://localhost/Templates/Grab_Url.php?search=keyword&amp;tbl=links&amp;col=keyword&amp;max=1&amp;page=29"&gt;Link2&lt;/a&gt;';
var_dump(parse_url(strip_tags($link6))); echo '&lt;br&gt;';
echo __LINE__; echo '&lt;br&gt;'; echo '&lt;br&gt;';
?&gt;


It's not echoing something like this:

**array(2) { ["path"]=> string(57) "https://localhost/Templates/Grab_Url.php" ["query"]=> string(91) "search=keyword&tbl=links&col=keyword&max=1&page=29" }**

Instead, I see crap like this:

**array(1) { ["path"]=> string(5) "Link2" }**
Copy linkTweet thisAlerts:
@tracknutJun 05.2021 — Double-check what you get from this:

strip_tags($link5);
[/quote]

It's definitely not what you think it is.
Copy linkTweet thisAlerts:
@developer_webauthorJun 09.2021 — @tracknut#1632598

Are you asking me to check what this code is echoing ?
<i>
</i>&lt;?php
$link5 = '&lt;a href="https://localhost/Templates/Grab_Url.php?search=keyword&amp;tbl=links&amp;col=keyword&amp;max=1&amp;page=29"&gt;Link5&lt;/a&gt;';
print_r(parse_url(strip_tags($link5))); echo '&lt;br&gt;';
echo __LINE__; echo '&lt;br&gt;'; echo '&lt;br&gt;';
?&gt;


Ok. It is echoing:

**Array ( [path] => Link5 )

4**


Is that what you expected ?

You said, it's definitely not what I think it is. So, tell me, what did I think it is ?

I was expecting to get echoed a url. (With the html tags removed, the browser should not render it as a link but a url only. That is what I was expecting).

What did you think I was expecting ?
Copy linkTweet thisAlerts:
@tracknutJun 09.2021 — @developer_web#1632730

No, I'm asking you to check what this code is echoing:
<i>
</i>$link5 = '&lt;a href="https://localhost/Templates/Grab_Url.php?search=keyword&amp;tbl=links&amp;col=keyword&amp;max=1&amp;page=29"&gt;Link5&lt;/a&gt;';
echo strip_tags($link5);

I think you're expecting it to have a url in it, which it doesn't. Hence nothing for parse_url() to parse.
Copy linkTweet thisAlerts:
@developer_webauthorJun 18.2021 — @tracknut#1632739

Sorry for the late reply. I have not been well lately and did not logon to my pc.

It is echoing:

**Link5**

So, what is your point ? I am not that bright figuring technician's minds out.

**EDIT:**

I was expecting it to echo:

**https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29**
Copy linkTweet thisAlerts:
@SempervivumJun 18.2021 — @developer_web#1633101 I'm not tracknut but I hope I can clarify:

strips_tags does exactly what it's name is indicating.

Tags are:

`&lt;a href="https://localhost/Templates/Grab_Url.php?search=keyword&amp;tbl=links&amp;col=keyword&amp;max=1&amp;page=29"&gt;</C><br/>
and the closing one:<br/>
<C>
&lt;/a&gt;</C><br/>
strip_tags removes these and what's left is <C>
Link5</C>, the text content.<br/>
<C>
https://localhost/Templates/Grab_Url.php?search=keyword&amp;tbl=links&amp;col=keyword&amp;max=1&amp;page=29</C> is the value of the attribute <C>href`
. If you intend to get this you would have to extract it by use of a regular expression. Or parse the complete document bei DOMDocument and get the attribute, which would be kind of an overkill.
Copy linkTweet thisAlerts:
@developer_webauthorJun 19.2021 — @tracknut#1632739

Your code is actually echoing (extracting) the Anchor Text. I wanted to echo (Extract so to speak) to url from the link. Not the anchor text.

However, in the very near future, I would've most likely open another thread asking how to extract or echo the anchor text from the link. And you just saved my time here.

Thanks!

I hope you engage in my threads more often. Because, I now understand, even if you don;t understand my question then you're likely to write me a sample code that I would need in the future. It's as if you time travelled and saw what I would need and wrote me the sample code in advance. Your code will be handy when I build my web crawler or spider. Bot. :)

PS - I'll tag you from time to time, especially when I build my spider (if I remember you and remember to do it, that is). ;)
Copy linkTweet thisAlerts:
@tracknutJun 21.2021 — @developer_web#1633142 please don't tag me. I've come to the conclusion that you and I don't speak the same language and I don't have a way of helping you. I've answered several of your questions, and in each one you've managed to come up with an explanation as to why my answer wasn't correct. Obviously my methods don't work for you.
Copy linkTweet thisAlerts:
@developer_webauthorJun 24.2021 — @tracknut#1633182

>>I've answered several of your questions, and in each one you've managed to come up with an explanation as to why my answer wasn't correct.<<

What! You've answered several of my questions and on all of them I rejected them ?

Ok, Show me where I rejected them apart from my post above. Frankly, I was complimenting you on my above post saying you saved me time from opening another thread asking another question as you answered it here. And yes, I did say you did not understand my question in this thread.

Copy linkTweet thisAlerts:
@developer_webauthorJun 24.2021 — @Sempervivum#1633104

Ok. I understand now what you're saying and maybe what TrackNut was trying to hint to me.

I thought, if I got this:

<a href="https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29">Link 5</a>

And I strip the tags, then I would be left with this:

a href="https://localhost/Templates/Grab_Url.php?search=keyword&tbl=links&col=keyword&max=1&page=29" Link 5.

The opening & closing html tags removed. That's what I originally thought.
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...