-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 の echo ステートメントを使用しています:$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

さらに説明が必要な場合は、さらに説明できますが、非常に簡単です。最初と最後の段落なしでコンテンツを出力し、最後の段落を個別に出力することもできます。

参照:デモ

于 2013-03-21T23:35:07.947 に答える
0

提供された画像からわかるように (次回は実際のコードを提供してください!)、文字列は二重の改行で区切られています。その場合、次のことができます。

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

これにより、各段落の配列が得られます。

属性をそのままにしておくことを検討してください。<small>および<footer>HTML タグを使用して、そのように指定します。

于 2013-03-21T23:31:08.597 に答える