Reputation: 509
I would like to retrieve the content of a textarea per line. So the user entered one link per line in that area.
Here is my code:
$links_in_textarea = get_field('links_in_textarea');
$link_trim = trim($links_in_textarea);
$link_single = explode("\n", $link_trim);
$link_single = array_filter($link_single, 'trim');
// displaying links in a list
for ($i=0; $i<=count($link_single); $i++) {
echo "<li><a href='http://$link_single[$i]'>List Item</li>";
}
My problem: When I click on a list item, the link comes with the following additional string:
%3Cbr%20/>
Anyone can see the reason for this? How do I need to modify the code above so that I can retrieve the link WITHOUT this additional string?
Upvotes: 0
Views: 50
Reputation: 2988
That's a <br>
which is url encoded. You can eliminate it with a simple string_replace
. This could look like this:
$links_in_textarea = str_replace('<br/>', '', $links_in_textarea);
Upvotes: 1
Reputation: 73
Sorry, I can't comment on your answer (don't have enough reputation) : I'd suggest you run this piece of code, which is quite similar :
$links_in_textarea = str_replace(array('<br>', '<br />', '<br/>'), '', $links_in_textarea);
Feel free to read PHP's documentation about that : https://www.php.net/manual/en/function.str-replace.php#example-4915
Upvotes: 0
Reputation: 350
You can use strip_tags
to remove any html tags from it. So you will have string without any html tags.
Upvotes: 0