WYSIWYG editor ruining my headlines - php

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

Related

Str_replace issue when using html

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.

HTML tags not being rendered when data is inserted using CKEditor

I'm building a simple blog system with PHP, mysqli, jquery, AJAX and CKEditor editor.
When I format my text in the CKEditor (or TinyMCE, doesn't matter) and save it in my database everything is OK. However when I print the text back, surprisingly, my browser won't render the html tags and displays them as plain text!
I have checked and I don't have any kind of CDATA in the page, that might cause the issue.
Here is how it renders:
How it renders
However, when inspecting the issue with FireBug, I noticed a lot of spaces before the tag is being printed! If I just make a small change in the spaces (Remove one or add another), then the browser will render the tags and display the text properly!!
Can you guys help me with this issue? It's really weird.

preventing nicEdit from creating foreign tags

Am using nicEdit to post content into my database. But I found out that when I post the content, it creates a bunch of tags such as div, p, tags per every paragraph created. This is causing my website to distort when I load the content onto the site.
Why is nicEdit creating all these unwanted div, p tags and is there anyway I can prevent that from happening???
EG.
When I input data eg. "This is a very good website" nicEdit adds tags like <div><p>This is a very good website</p></div> to the text! Which shouldn't be the case.
You're using nicEdit for all the wrong reasons if the end result isn't supposed to be HTML.

Creating and displaying full details

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.

how to add photos to PHP blog postings using admin page

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.

Categories