SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to show word from right to left?

    Some language must read from right to left.

    and I have to create website that read from right to left and IE should go to new line correctly.

    Can I do this with PHP?

    Thanks.
    Last edited by itsource; Jul 20, 2003 at 22:07.
    I live in Thailand. My English grammar not well.

  2. #2
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if your words are as an array, then you could do this:
    PHP Code:
    $array = ( "we""like""to""eat""food" );
    $array  array_flip($array);
    foreach(
    $array as $key => $value)
    {
        print 
    $value."\s";

    which will print
    Code:
    food eat to like we
    Ryan

  3. #3
    SitePoint Zealot JordanTLClive's Avatar
    Join Date
    Feb 2001
    Location
    Las Vegas, NV
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to exand upon Ryan's point, if your text isn't in an array, you can put it into an array and still use his code:
    PHP Code:
    $string 'This is my text.'
    $array explode(' ',$string);
    // Continue with Ryan's code...
    $array array_flip($array);
    foreach(
    $array as $key => $value)
    {
    print 
    $value "\s";

    -Jordan

  4. #4
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank but It's work only 1 line string.

    for example

    if I have 3 line of string like this
    ------------------------------
    one two three
    four five six
    seven
    ------------------------------

    The result is
    ------------------------------
    seven six five
    four three two
    one
    ------------------------------

    It should be this
    ------------------------------
    three two one
    six five four
    seven
    ------------------------------
    I live in Thailand. My English grammar not well.

  5. #5
    SitePoint Zealot JordanTLClive's Avatar
    Join Date
    Feb 2001
    Location
    Las Vegas, NV
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try something like this:
    (I've used br tags in this example instead of \n for the purpose of testing in a browser)

    PHP Code:
    <?php
    $string 
    'This is my text.<br>
    It has multiple lines'
    ;
    // Fill array with string using <br> as seperator
    $lines explode('<br>',$string);
    // Loop through array elements
    foreach($lines as $line)
    {
         
    // Seperate line by spaces
         
    $array explode(' ',$line);
         
    // Reverse elements of the new array
         
    $array array_reverse($array);
         
    // Output each element in the new order
         
    foreach($array as $key => $value)
         {
              print 
    ' ' $value;
         }
         
    // Insert <br> again to go to a new line
         
    print '<br>';
    }
    ?>
    -Jordan


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •