The code to search and find the URLs works perfectly, the issue I have is with editing them out of the Post Text.
Having tried and failed with the
generate_text_for_edit
, generate_text_for_display
and generate_text_for_storage
I found that knowing the format the data was stored in the database enabled me to edit the text quite simply by using str_replace
.
Code: Select all
// $posttext is read from the database before editing
$a = "http://example.com";
$toremove = '<URL url="' . $a . '"><s>[url]</s>' . $a . '<e>[/url]</e></URL> <br/>';
$posttext = str_replace($toremove, "", $posttext);
$postchecksum = md5($message_parser->$posttext)
$postext
and $postchecksum
(Also the post_edit_time, post_edit_user, post_edit_count and post_edit_reason are updated but I think that has no bearing on the issue)
On page refresh the Post is displayed correctly without the offending URL but in the database there is a blank line where the URL once was.
I did try the
generate_text_for_storage
after the above code but that seemed to have no effect.While things are working how they are intended, I'm sure that the blank line in the database should not be there and would like to fix that.
What am I missing or not yet understanding ??
EDIT
Tried using
$posttext = str_replace($toremove, "Link Removed by Admin", $posttext);
in the above code and found that it appears differently in the Post and database.In the Post the 'Link Removed by Admin' is displayed as
Removed by Admin followed by whatever came next in the Post
with no 'New Line' after the 'Removed by Admin' but there is a space.In the database the 'Link Removed by Admin' is displayed on it's own line with whatever came next in the Post beginning on the next line.
It would appear that there is a <br/> being added somehow in the database but so far I cannot see where it might be.
The only <br/> I can see comes at the end of the link and that should be removed by the str_replace.