-1

我正在从一个项目的数组中打印出一些数据,但我想删除第一段和最后一段。但是保留最后一段以单独归因于它自己的输出。

我想删除第一段开头From Wikipedia, the free encyclopedia.和最后一段,开始Description above from the Wikipedia article Humphrey Bogart, licensed under CC-BY-SA, full list of contributors on Wikipedia.

要调用该行,我只是使用一个简单的 PHP 回显语句:$actor_biography = $actor_details['biography'];,在回显之前$actor_biography

代码:

Array
(
    [adult] => 
    [also_known_as] => Array
        (
        )

    [biography] => From Wikipedia, the free encyclopedia.  

Humphrey DeForest Bogart (December 25, 1899 – January 14, 1957) was an American actor. He is widely regarded as a cultural icon. The American Film Institute ranked Bogart as the greatest male star in the history of American cinema.

After trying various jobs, Bogart began acting in 1921 and became a regular in Broadway productions in the 1920s and 1930s. When the stock market crash of 1929 reduced the demand for plays, Bogart turned to film. His first great success was as Duke Mantee in The Petrified Forest (1936), and this led to a period of typecasting as a gangster with films such as Angels with Dirty Faces (1938) and B-movies like The Return of Doctor X (1939).

His breakthrough as a leading man came in 1941, with High Sierra and The Maltese Falcon. The next year, his performance in Casablanca raised him to the peak of his profession and, at the same time, cemented his trademark film persona, that of the hard-boiled cynic who ultimately shows his noble side. Other successes followed, including To Have and Have Not (1944), The Big Sleep (1946), Dark Passage (1947) and Key Largo (1948), with his wife Lauren Bacall; The Treasure of the Sierra Madre (1948); The African Queen (1951), for which he won his only Academy Award; Sabrina (1954) and The Caine Mutiny (1954). His last movie was The Harder They Fall (1956). During a film career of almost thirty years, he appeared in 75 feature films.

Description above from the Wikipedia article Humphrey Bogart, licensed under CC-BY-SA, full list of contributors on Wikipedia.
    [birthday] => 1899-12-25
    [deathday] => 1957-01-14
    [homepage] => 
    [id] => 4110
    [imdb_id] => nm0000007
    [name] => Humphrey Bogart
    [place_of_birth] => New York City, New York, USA
    [popularity] => 3.92
    [profile_path] => /5WaI2QbYd6WYq7Mzk3tEUTXSM3u.jpg
)
4

2 回答 2

1
$para = 'Pellentesque quis sodales nunc. Integer mi lacus, hendrerit posuere adipiscing sed, sagittis non lectus. Fusce eleifend felis enim. Curabitur sagittis libero neque. Proin a tortor eros, interdum interdum metus. Pellentesque non quam non sem commodo facilisis. Duis fermentum sollicitudin gravida. Sed eros lorem, rutrum ac viverra nec, tempor id nulla. Integer congue malesuada massa? Sed porttitor varius felis, sit amet pharetra metus consequat fringilla? In non leo metus, eget tristique arcu? In magna mauris, mollis blandit posuere id; pulvinar vel libero. Ut vel augue vel leo semper interdum lobortis a magna. Nunc ac elit ipsum; vitae mollis eros. Phasellus erat sem, elementum semper vehicula eu, cursus et neque. Ut ac lorem felis.

Maecenas vel urna felis. Maecenas sed ante libero, sit amet consectetur neque. Duis eget eros ligula, non varius neque. Etiam sit amet interdum mi. Praesent ac sapien gravida ante congue suscipit! Pellentesque feugiat velit sed enim semper vitae gravida lorem mattis. Donec dapibus odio vitae velit laoreet laoreet!

Nam et turpis magna. Aliquam ultrices leo in lectus venenatis id facilisis nisl iaculis. Fusce euismod, ipsum dignissim pharetra iaculis, turpis lectus iaculis magna, vel adipiscing arcu arcu in nibh. Sed ullamcorper faucibus massa vel tincidunt. Nunc condimentum ornare mi, ut tempus erat vehicula tempor. Sed pulvinar nulla at tortor lacinia auctor. Proin eget enim diam, in adipiscing diam. Praesent neque arcu, pellentesque vel gravida nec, elementum et ante? Quisque blandit, nulla id semper pellentesque, eros dolor laoreet dui, sit amet placerat libero libero non ligula. Praesent commodo dictum viverra. Proin egestas diam a nunc dapibus eu sollicitudin turpis semper? Etiam at tincidunt magna. Phasellus ullamcorper eros sit amet massa convallis ut molestie orci vestibulum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fringilla, ante vel facilisis venenatis, sapien leo accumsan mi, id ultrices nibh lectus id orci. Donec dignissim sapien a risus tempor hendrerit.

Proin egestas libero id diam dapibus non accumsan lacus cursus. Cras vel lectus ut ligula condimentum interdum eget fringilla magna. Suspendisse pulvinar sem lacus, at facilisis lectus. Vestibulum elit sapien, semper vel commodo nec; ultrices nec lorem. Quisque erat dui, faucibus at convallis nec, aliquam in nulla. Donec vulputate libero in sapien dictum vel feugiat turpis bibendum! Duis nec mauris libero, a hendrerit risus. Integer tempus, magna in aliquet volutpat, sapien dui sagittis ante, ut convallis sem purus at diam. Proin auctor, nisi sed sagittis vulputate, leo arcu commodo lorem; vel convallis quam quam ut nisl! Curabitur hendrerit dolor id mi hendrerit eget lobortis nibh sollicitudin. Vestibulum aliquet; libero eleifend placerat posuere, lorem est molestie nunc, id pellentesque nisi massa nec ligula.

Praesent urna nisi, rhoncus scelerisque cursus vitae, condimentum quis augue. Duis ac lacus eget eros dignissim auctor. Duis at nunc eros! Nulla rutrum ullamcorper nisi, ac fermentum dui varius quis. Cras condimentum leo adipiscing augue tempor at lacinia elit suscipit. Pellentesque dui est, feugiat sed accumsan ac, aliquam id risus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean nec felis quis velit faucibus aliquam eget ac tellus. Praesent congue velit ut metus placerat sed ultrices enim egestas.';

$start_sec = strpos($para, "\n");  // get start position of 2nd paragraph
$start_end = strrpos($para, "\n"); // get start position of last paragraph

$new_para = trim(substr($para, $start_sec, $start_end - $start_sec)); // get substring of content until start of last paragraph
$last_para = trim(substr($para, $start_end)); // get substring of content from start of last paragraph until end

echo $new_para;  // output all paragraphs but first and last
echo $last_para; // output last paragraph

If you need more explanation I can explain some more, but it's pretty straightforward. It will output content without first and last paragraphs and also allow you to output the last paragraph separately.

See : DEMO

于 2013-03-21T23:35:07.947 回答
0

从您提供的图像中我可以看到(请下次提供实际代码!),字符串由双换行符分隔。在这种情况下,您可以这样做:

$result_array = explode("\n\n", $string);

这会给你一个包含每个段落的数组。

考虑保持属性不变。使用<small><footer>HTML 标签来指定它。

于 2013-03-21T23:31:08.597 回答