Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Example:

%body
The family is a central socialization context from early childhood
behavior \cite{dishi-sto2007,hengg-etal1998,johns-etal2005}.

Family management becomes more challenging for parents during the
transition from middle childhood to adolescence. Typically developing

Question: I need to the extract the content from the string "%body" to first paragraph. Am using
PHP
preg_match( '/%body\\n(.*?)\\n/', $text, $matches ); 
to extract. But output is "The family is a central socialization context from early childhood" as \n charcter is in all the lines. So how to find the \n character at index 0 using regex, so that I can extract by paragraph.
Posted

1 solution

Instead of Regex, try the PHP explode() Function[^]
<?php
$line = "%body
The family is a central socialization context from early childhood
behavior \cite{dishi-sto2007,hengg-etal1998,johns-etal2005}.

Family management becomes more challenging for parents during the 
transition from middle childhood to adolescence. Typically developing ";

$array = explode("\n\r", $line);
echo $array[0];

?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900