php - Script that recognizes first sentence, put it inside a heading and the rest inside a paragraph -
Hey, I have this code, I take a WordPress post content, put it in a variable and from the first sentence Matches it, put it inside an H2 heading and in the remaining paragraphs.
1. The problem is ... my script only recognizes. Or! Or? At the end of the first verse, can I recognize it "suspension"? 2. If I have such text in my WordPress post: First sentance! Continue with more text My script only shows "only the first grace" from some text, and after entering nothing, I hit it ? And ideas? Here is the code: It should be done without too much confusing < Strong> updates about the second question. That's because the rule The expression line ends on the break.If you are not mistaken, then you have the option of
ob_start (); content (); $ Old_content = ob_get_clean (); // I have a variable $ content = strip_tags ( $ Old_content) Insert WordPress inside; // I'll use the strip tag preg_match ('/(.* ?????? !!)) (. *) /', $ Content, $ match); $ First_stent = $ match [1]; $ the_rest = $ match [2]; if ($ first_centre! = '' And amp ; $ The_rest! = ''): Reverberation '& lt; h2 & gt;' $ First_sentence. '& Lt; / h2 & gt;'; echo & lt; p & gt; '$ the_rest.' & Lt; / p & gt; 'Else: echo & lt; h2 & gt; about me: & lt; / h2 & gt; if;; end; < P>
preg_match ('/ (. *? [??!] {1,3}) (. *) /', $ Content, $ match);
... ,
!!! ,
??? , but keep in mind that
.!? will also fit. Unfortunately I am unable to perform some more complex tests at this time.
'/ (. *? [?!!!] {1,3}) (*. *) / M' But I suggest changing this code:
preg_match ('/ (. *? [?!.!] {1,3}) / ', $ Content, $ match); $ first_cent = $ match [1]; $ The_rest = substr ($ content, strlen ($ first_centence));
Comments
Post a Comment