Reputation: 547
Hi I'm working on some formatting for mobile devices and according to my sources they work best with 37 characters per line.
Let's say I input a string into a form that is 'normal' say 80 characters per line such as :
INPUT:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eget risus porta, sodales ligula sed, ultricies sem. Praesent cursus, erat et consequat cursus, ante nisl placerat neque, ut maximus massa ipsum quis turpis. In mollis viverra nisl vitae pellentesque. Ut et tristique nisi. Duis nec lacinia enim. Vestibulum ultricies risus sed nibh imperdiet, nec venenatis libero suscipit. Morbi accumsan purus lectus, et commodo risus blandit at. Morbi luctus lacus dapibus, tempus est et, sollicitudin est. Phasellus sodales sodales eros. Proin dapibus pulvinar diam, ut pretium nisl pulvinar a. Donec nec lectus urna. Curabitur eu dolor pharetra, facilisis metus vitae, consectetur orci. Curabitur quis egestas mi, non tincidunt nisl.
I'd like the routine to put /n at around the 37 character mark so that it is easily readable on screen for mobile devices.
OUTPUT:
Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Fusce
eget risus porta, sodales ligula sed,
ultricies sem. Praesent cursus, erat
et consequat cursus, ante nisl
placerat neque, ut maximus massa
ipsum quis turpis. In mollis viverra
nisl vitae pellentesque. Ut et
tristique nisi. Duis nec lacinia
enim. Vestibulum ultricies risus sed
nibh imperdiet, nec venenatis libero
suscipit. Morbi accumsan purus
lectus, et commodo risus blandit at.
Morbi luctus lacus dapibus, tempus
est et, sollicitudin est. Phasellus
sodales sodales eros. Proin dapibus
pulvinar diam, ut pretium nisl
pulvinar a. Donec nec lectus urna.
Curabitur eu dolor pharetra,
facilisis metus vitae, consectetur
orci. Curabitur quis egestas mi, non
tincidunt nisl.
Each line has a carriage return at 37 columns keeping words consistent.
This is part of an API we are writing and we need a /n written into the variable of the output string.
The input string is a form field i.e.
$input=$_POST['input'];
OUTPUT
<textarea name="str" id="textarea" cols="80" rows="20">
[print $output code goes here]
</textarea>
A number of you are asking me why I'm wanting to do this. Here's the reason: specifically my instructions are to take a text input string and turn it into 18 point Tahoma with 37 characers with a <br>
at the end of each line. I can do that part no problem, once I have a string with new lines or carriage returns, so I'm just breaking this post down into a simple string question rather than a debate in mobile email philosophy!
Hi when I input text that has punctuation like an apostrophe (') into a form and then feed that input back into a <textarea>
it adds an extra \ to the output. I tried str_replace but it doesn't seem to remove it.
Input:
Additional Strategies To This Case Study – Apply These To Propel Search Triggers’ Power To The Fullest!
Keep an 'arsenal' of keyword phrases, which you then 'sprinkle' into your titles, tags, and text from time to time. That's really the key. Finding those initial words you're pursuing is the most important factor. And then being consistent with your content on the site over spans of time, strategically incorporating the words you generated from Search Triggers (ST).
OUTPUT
Additional Strategies To This Case
Study – Apply These To Propel
Search Triggers’ Power To The
Fullest!
Keep an \'arsenal\' of keyword
phrases, which you then \'sprinkle\'
into your titles, tags, and text from
time to time. That\'s really the key.
Finding those initial words you\'re
pursuing is the most important
factor. And then being consistent
with your content on the site over
spans of time, strategically
incorporating the words you generated
from Search Triggers (ST).
How can I remove the \ before the apostrophe's in the output string on a text area?
$str = str_replace( '', "\", $str);
is invalid because the \ is treated as a literal. Thanks!
Upvotes: 1
Views: 37
Reputation: 547
The function wordwrap did the job. I didn't know such a function existed. Thank you!
<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");
echo $newtext;
?>
Upvotes: 0
Reputation: 1940
The php function wordwrap might help you achieve what you want
http://php.net/manual/en/function.wordwrap.php
Upvotes: 1