I have a community web site and I want that users write
you can specify dir="rtl" in your html tags for the correct presentation with php
in your CMS or if you aren't using one, when storing the context to the DB you can have a option to store a variable with the direction of text the author used.
So, when fetching the post, you can also fetch the option the author marked.
otherwise, like the fellow programmers have suggested, parse the content and see if its arabic characters or latin characters.
example
without more information on how you are publishing your posts, i can't detail much more. please provide how you are storing your posts and how you are fetching them.
I've built a site using this tecnique and i deal with arabic rtl content everyday. it's very simple:
a working example of dir="rtl"
jsfiddle.net
reference: w3.org