0

I am trying to build a system where users can edit news stories. When they add images to the stories they will type #IMG1# if it is the image with id 1 they want in there.

When they upload the news, the #IMG1# code is str_replace() with something like this: <div id="image"><img src="images/image1.jpg"></div>

The issue for me is when they want to edit the news again, I want to replace all the image codes back, so the user sees the #IMG1# again, but it seems I cannot str_replace() back because of the html codes and the quotation marks? Is this true?

Is there a way to fix this?

5
  • 1
    Store your data with #iMG# but replace this #IMG# when you output news item, not on save. Commented Mar 26, 2020 at 8:51
  • @u_mulder I am not following you here. I have no issue showing the stuff I want, that works perfectly. The issue is when editing the news again, then I want to show the #IMG1# instead of the entire html code because it is not showed properly in the editor. Commented Mar 26, 2020 at 8:52
  • Do not replace #IMG1# with <img> when you save data. Commented Mar 26, 2020 at 8:53
  • Seems like a better solution now yes, I'll try that! Commented Mar 26, 2020 at 8:54
  • Thank you @u_mulder that was way easier! Commented Mar 26, 2020 at 8:59

1 Answer 1

3

I advise to leave news' text as is, with #IMG1# placeholders.

Only when you output this text for viewing - replace #IMG1# with <img> tag, but when user edits text - he still sees #IMG1# and can edit it.

Of course, as you will replace #IMG1# placeholders on each output, this can slower your system. As a solution - you can add additional field like renderedContent and on saving data render news text to this field and when output for viewing - take content from this field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.