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?
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.
Related
I just added WYSIWYG editor to my blog so I can easily post articles with text formatting. However, since I also got a box with recent posts, it automatically adds the text format (text bold, white lines etc) to those headlines. One headline contains the Title, abit of a content and the amount of reactions. Like:
BLOGTITLE
Abit of the article content
2 likes
Is there a way I could just show the content without the text formatting? I tried str_replace but that aint working for me. I also tried the striplashes. Doesnt work.
I dont think you need a piece of code since I'm simply echo'ing the message in the database.
It sounds like you need strip_tags
I'm having some trouble with CKEditor.
I have created a blog for my website and a back end section to write new posts and approve comments etc. It's all working fine and I use CKEditor to write and edit posts.
When writing a text only post its fine, it gets stored in the database and subsequently appears on the website as it should. But If I write a post with an image in it it doesnt get stored in the database. All text and images disappear.
The title of the post goes into the database as this is just using a normal text box. But everything in the CKEditor disappears if I put an image in there.
Here are some screen shots:
I press the image button and enter in the explicit URL of the image stored on my server. (http://www.mydomain.com/images/image.jpg)
When I press ok the image is visible in CKEditor with the text above it.
When I submit the post and then return to it to view or edit it, the CKEditor is empty and only the Title is there. Checking the database I can see the title is entered but the body isnt.
If I dont enter an image everything works fine title and body go into the database and the blog post appears on the site.
Does anyone have any idea whats wrong here?
I actually discovered the answer myself
The image tags created in the CKEditor would be something like
<img src="images/picture.jpg">
and my SQL query would be something like
$query = "INSERT INTO Table (blog_body, blog_title) VALUES ('".$blogBody."','".$blogTitle."')";
or something along those lines.
To solve it I just swapped the quotation marks around. Placing the query in single quotes and swapping the quotes about the variables around.
This fixed my problem.
Just thought if someone else is having this trouble this may help
I've developed a website for my rugby club. We currently have one page with news articles on it (each with there own unique id's per story).
What I'd like to do is have a separate page for each story, then show a snap-shot of that story (say headline and first paragraph) on a Headlines page.
How could I do this? Via javascript or php? (forgive a neewbie)
Use a headline field and a text field in your Article table.
To extract the first paragraph of the text, use the explode function.
$paragraph = explode("\n", $text);
echo $paragraph[0];
If your text contains <p></p> :
$paragraph = explode("</p>", $text);
echo $paragraph[0];
You can use Links With URL Preview from Easiest Tooltip and Image Preview Using jQuery.
See the Example 3:
Example 3: Links With URL Preview
This demands a bit more effort but it might be worth it as an extra feature to add to your sites. What you’ll need here is a small size screenshot of the target url. You’ll put screenshot image location in in REL attribute of the A tag and script will do the rest.
One way could be to use jQuery's load() feature to grab the article page, and trim out stuff you don't need. I wouldn't necessarily recommend this though as the loaded file counts as a page visit, and could screw up your analytics.
Are you using a CMS? This is a fairly standard feature of systems such as Wordpress, Joomla, Perch, etc.
I have mini forum site im coding and when users make their profile they get to add a little info about themselves. I want them to be able to make list elements and add images into this description, as well as make /n (drop a line). How can I do this from a simple input text area? is there any jQuery text area plugins someone can recommend.
As it stands I have the users start any list elements (bullet points) with * and then just septate out the lines and stick them in list elements, for images I make them upload the image, they get a ref number and put that in the box between two sets of ++.
This is not very user friendly, anyone have any suggestions or plug-ins i could use to better this?
Sounds like you need a HTML editor such as TinyMCE. This will change a textarea into a HTML editor, which will give your users the ability to format the content with lists and images etc etc.
have a look at the following plugins available for your need. CL Editor, [CK Editor] (http://ckeditor.com/), TinyMCE.
I managed to create a simple blog and an admin page using PHP. I didn't use a CMS like wordpress because I wanted a deeper understanding of PHP.
I wanted to create an admin page that allowed the user to specify where in their blog posting they could put in a picture; for example, they can add a photo before the first paragraph or after.
My admin page as it is now is just a textarea input field and a submit button that submits text-only blog posts from the textarea field to the database. My thought process was that I could add img tags into the textarea input field, but the user's photos might be stored on their hard drive so I thought of the idea to store PHP code in the textarea input field to retrieve image files from the database. For example, if I wanted to place a photo after the first paragraph of the blog post, I would type something like this into the textarea field:
This is the first paragraph. Here is a photo of my vacation:
<? echo "<img src='getPhoto.php?page=blogPost'>"; ?>
Then I click the "submit button" and the paragraph with the PHP code gets submitted into my database. The page with the blog posting retrieves the text, "This is the first paragraph. Here is a photo of my vacation:" and the PHP code. The PHP code then retrieves and shows the photo.
The problem is that submitting PHP code with the blog text might be confusing for a user who is not tech-savvy or does not have any programming knowledge. The admin page should make it possible for the blog writer to place photos anywhere in their blog post without programming knowledge. I haven't found a tutorial yet that covers image placement in a PHP blog's admin page. Any help getting started would be appreciated.
One way to accomplish what you want is by implementing custom shortcodes. In you case it'd look something like this:
This is the first paragraph. Here is a photo of my vacation:
[image bahamas-00123]
How it works is that you do something like this:
$text = shortcodes($text);
You'd need a separate area for uploading photos and some way of keeping track of them (ie: sql, flatfiles) so you know that bahamas-00123 actually refers to /some/path/DSC-00123.JPG.
For some code please check the accepted answer of: How do I replace custom “tags” in a string?
You can use a text editor like ckeditor or tinymce to format the text and upload images. This way users need not be aware about the custom tags and they can place the image wherever they like.