I have some text that I get from the database like this:
$solution = $row['solution'];
Then I have some HTML I create in PHP using that variable like this:
echo '<a class="delete_suggested_solution" data-problem_id="'.$problem_id.'" data-suggested_solution_id="'.$suggested_solution_id.'" href="#">Delete</a> | <a href="#" class="edit_suggested_solution" data-problem_id="'.$problem_id.'" data-suggested_solution_id="'.$suggested_solution_id.'" data-solution_text="'.$solution.'" data-solution_title="'.$solution_name.'">Edit</a>';
That actually works fine in most cases, but when the $solution has a link in it like this <a href="http://SomeUrlWhatever.com">something</a> then this HTML breaks the HTML on the page when it is displayed.
Is there something that can be done so that the HTML on the page does not become broken for me?
Thanks!!
Assuming the part you want here is
somethingand not the link, just usestrip_tags()andhtmlentities()to retrieve only the tag’s inner text content, and encode quotes to be used inside HTML attributes.