View Full Version : RTL with strings and arrays
madshadow
05-12-2006, 12:59 AM
Hello all,
I have some problems concerning "rtl" issues:
I'm making a sort "typewriter" for a language that uses strange characters that do not appear in any font. i've come up with a system whereby the user types a sentence using regular latin characters (you have to know the pre-determined way of spelling things). Next I put the string into an array to apply some formatting then put it back into a string and reverse it.
Next, I do a for loop that runs through each character and outputs an image based on the character. The result is basically a graphic representation that is sort of like a bunch of scrabble tiles.
My problem lies in the fact that i have successfully made it right to left by reversing the string order, but as a result of my method when the final product takes up more than one line, the first line is below the second line, etc.
I hope all this makes sense....if anyone can help me figure out how to make it properly look like right-to-left writing that goes from top to bottom please let me know. also, if there is a better process than the one i have used already please mention it.
I really appreciate any help that anyone can provide. Thanks!
ralph l mayo
05-12-2006, 03:46 AM
I don't really get what you're saying. If the problem is that you don't want it to wrap to the next line on long entries, wrap each line in a <nobr> tag.
madshadow
05-12-2006, 03:58 AM
I don't really get what you're saying. If the problem is that you don't want it to wrap to the next line on long entries, wrap each line in a <nobr> tag.
Thanks for replying...perhaps an example would help (even though my output would be a series of images).
Lets say the user entered the phrase:
"this is an example of what i might submit"
My script would output:
timbus thgim i
tahw fo elpmaxe
na si siht
What I want to achieve is this:
na si siht
tahw fo elpmaxe
timbus thgim i
thanks for replying....i hope this made more sense
ralph l mayo
05-12-2006, 04:17 AM
<?php
$text = 'timbus thgim i
tahw fo elpmaxe
na si siht';
$lines = explode("\n", $text);
$lines = array_reverse($lines);
?>
This will reverse the lines, and it should work ok with the images too, but you may have to change the explode delimiter to '<br />' depending on how you're doing things. If you have trouble post some example image HTML output.
(edit for less stupid method)
madshadow
05-12-2006, 04:37 AM
<?php
$text = 'timbus thgim i
tahw fo elpmaxe
na si siht';
$lines = explode("\n", $text);
$lines = array_reverse($lines);
?>
This will reverse the lines, and it should work ok with the images too, but you may have to change the explode delimiter to '<br />' depending on how you're doing things. If you have trouble post some example image HTML output.
(edit for less stupid method)
ralph l mayo...first of all thank you so much for your ongoing help. the problem that arises with your solution above is that you dont know how long the string is nor where there are line breaks. the line breaks occur based on the width of the page. I have included an excerpt of relevent code below...and i'm not very advanced so i apologize if it is very messy and there are many unnessary steps. if you'd like to see the actual page you can go to http://www.solitreo.com/engines/calculator14.php
thanks again...i really appreciate it
<?php # calculator.php )
$page_title = 'Typewrite Ladino';
include ('./includes/header13.html');
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {
if (!empty($_POST['from']) && !empty($_POST['to']) && !empty($_POST['message'])) {
// Print the heading.
echo '<h1 id="mainhead">Typewrite Ladino</h1>';
echo '<p>Sent from ' . $_POST['from'] . ' to ' . $_POST['to'] . ' saying ' . $message . '.</p>';
// Print some spacing.
echo '<p><br /></p>'
function applyformat () {
$preformat = $_POST['message'];
$temparray = explode(" ", $preformat);
foreach($temparray as $word) {
$pattern1 = "a$";
$pattern2 = "m$";
$replace1 = "h";
$replace2 = "M";
$word = ereg_replace($pattern1, $replace1, $word);
$word = ereg_replace($pattern2, $replace2, $word);
$postarray[] = $word;
} //ends foreach loop
$postformat = implode (".", $postarray);
$revpostformat = strrev($postformat);
$revlength = strlen($revpostformat);
$n = strlen($postformat);
$end = $n;
$inc = 1;
//to show reversed string
print ("reverse reverse." . "$revpostformat" . "<BR>");
for ($current = 0; $current <= $revlength; $current++) {
$character = substr($revpostformat, $current, $inc);
//output the graphics
switch ($character) {
case "a":
print("<IMG SRC=webletters\\\aleph.gif>");
break;
case "b":
print("<IMG SRC=webletters\\bet.gif>");
break;
case "g":
print("<IMG SRC=webletters\\gimel.gif>");
break;
case " " :
print("<IMG SRC=webletters\\space.gif>");
break;
default:
print("$character");
break;
}
}
} //ends applyformat define
applyformat(); //call applyformat function
} else { // Invalid submitted values.
echo '<h1 id="mainhead">Error!</h1>
<p class="error">Please enter a valid information.</p><p><br /></p>';
}
} // End of main isset() IF.
ralph l mayo
05-12-2006, 04:44 AM
I don't know how you're goint to reverse the line order if you don't know what constitutes a line. Maybe you can just make an arbitrary wrap width of N images, and then use array_chunk($array, N) to divide the lines? Or does that defeat the purpose of your formatting?
madshadow
05-12-2006, 04:50 AM
ralph... any suggestion as to how i might make sure that word isn't cut in the middle? is there something you can think of where i can tell it to break every x characters, but if that is in the middle of a word extend until the end of the word (ie until it gets to space)?
Thanks
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.