use text-align smartly (if english dir=ltr if arabic dir=rtl)

后端 未结 5 1420
北海茫月
北海茫月 2020-12-02 19:45

I have a community web site and I want that users write

  • English posts with direction LTR / text-align: left) and
  • Arabic posts with direction RTL / tex
5条回答
  •  不思量自难忘°
    2020-12-02 20:15

    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

提交回复
热议问题