Jump to content

Automatically insert images into text


l17wnj

Recommended Posts

You can put it in every x chatacters, the problem with lines is that at different resolutions the same amount of text will span a different number of lines.

 

EDIT:

 

It all depends on the sort of page layout and the fields you're using. Are you hoping to have a few paragraphs and put a picture in the middle, or do you have a number of fields you want to output from the db, then an image, then more fields?

Link to comment
Share on other sites

try

<?php
function my_chunk($text, $limit){
$out = array();
while (strlen($text)>$limit){
	$x = strrpos(substr($text,0,$limit), ' ');
	$out[] = substr($text,0,$x);
	$text = substr($text, $x+1);
}
if (strlen($text)) $out[] = $text;
return $out;
}
$test = "If the author should be told that the sentimental love of our day was unknown to the pagan world, he would not cite last the two lovers, Antony and Cleopatra, and the will of the powerful Roman general, in which he expressed the desire, wherever he might die, to be buried beside the woman whom he loved to his latest hour. His wish was fulfilled, and the love-life of these two distinguished mortals, which belongs to history, has more than once afforded to art and poesy a welcome subject.  In regard to Cleopatra, especially, life was surrounded with an atmosphere of romance bordering on the fabulous. Even her bitterest foes admire her beauty and rare gifts of intellect. Her character, on the contrary, presents one of the most difficult problems of psychology. The servility of Roman poets and authors, who were unwilling frankly to acknowledge the light emanating so brilliantly from the foe of the state and the Imperator, solved it to her disadvantage. Everything that bore the name of Egyptian was hateful or suspicious to the Roman, and it was hard to forgive this woman, born on the banks of the Nile, for having seen Julius Caesar at her feet and compelled Mark Antony to do her bidding. Other historians, Plutarch at their head, explained the enigma more justly, and in many respects in her favour.  It was a delightful task to the author to scan more closely the personality of the hapless Queen, and from the wealth of existing information shape for himself a creature in whom he could believe. Years elapsed ere he succeeded; but now that he views the completed picture, he thinks that many persons might be disposed to object to the brightness of his colours. Yet it would not be difficult for the writer to justify every shade which he has used. If, during his creative work, he learned to love his heroine, it was because, the more distinctly he conjured before his mind the image of this wonderful woman, the more keenly he felt and the more distinctly he perceived how fully she merited not only sympathy and admiration, but, in spite of all her sins and weaknesses, the self-sacrificing affection which she inspired in so many hearts.  It was an author of no less importance than Horace who called Cleopatra \"non humilis mulier\"--a woman capable of no baseness. But the phrase gains its greatest importance from the fact that it adorns the hymn which the poet dedicated to Octavianus and his victory over Antony and Cleopatra. It was a bold act, in such an ode, to praise the victor's foe. Yet he did it, and his words, which are equivalent to a deed, are among this greatly misjudged woman's fairest claims to renown.  Unfortunately it proved less potent than the opinion of Dio, who often distorted what Plutarch related, but probably followed most closely the farce or the popular tales which, in Rome, did not venture to show the Egyptian in a favourable light.  The Greek Plutarch, who lived much nearer the period of our heroine than Dio, estimated her more justly than most of the Roman historians. His grandfather had heard many tales of both Cleopatra and Antony from his countryman Philotas, who, during the brilliant days when they revelled in Alexandria, had lived there as a student. Of all the writers who describe the Queen, Plutarch is the most trustworthy, but even his narrative must be used with caution. We have closely followed the clear and comprehensive description given by Plutarch of the last days of our heroine. It bears the impress of truth, and to deviate widely from it would be arbitrary.  Unluckily, Egyptian records contain nothing which could have much weight in estimating the character of Cleopatra, though we have likenesses representing the Queen alone, or with her son Caesarion. Very recently (in 1892) the fragment of a colossal double statue was found in Alexandria, which can scarcely be intended for any persons except Cleopatra and Antony hand in hand. The upper part of the female figure is in a state of tolerable preservation, and shows a young and attractive face. The male figure was doubtless sacrificed to Octavianus's command to destroy Antony's statues. We are indebted to Herr Dr. Walther, in Alexandria, for an excellent photograph of this remarkable piece of sculpture. Comparatively few other works of plastic art, in which we here include coins, that could render us familiar with our heroine's appearance, have been preserved.";
$a=my_chunk($test, 300);
print_r($a);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.