Php 如何捕获第二个粗体文本并将其存储到数据库中?

Php 如何捕获第二个粗体文本并将其存储到数据库中?,php,mysql,Php,Mysql,假设将整个字符串存储到数据库中,将句子拆分,并将选项和答案存储到自己的列中 $example=“当她(看到,看到,看到,看)事故时,她去商店(买,买,买,买)一些零食。” 设法将整个字符串存储到数据库中,并将其存储到相应的列中,并且能够捕获第一个粗体文本并将其存储到数据库中 <?php define('DB_HOST', 'localhost'); define('DB_NAME', 'palmdatas'); define('DB_USER','root'); define('DB_

假设将整个字符串存储到数据库中,将句子拆分,并将选项和答案存储到自己的列中

$example=“当她(看到,看到,看到,看)事故时,她去商店(买,买,买,买)一些零食。”

设法将整个字符串存储到数据库中,并将其存储到相应的列中,并且能够捕获第一个粗体文本并将其存储到数据库中

<?php 
define('DB_HOST', 'localhost');
define('DB_NAME', 'palmdatas'); 
define('DB_USER','root');
define('DB_PASSWORD',''); 

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error()); 
$mode = $_POST['mode']; 
$question = $_POST['editor1']; 
$text = $question;

echo "\n";

$text = strip_tags($text);


function multiexplode ($delimiters,$string) {

$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return  $launch;
}

$exploded = multiexplode(array(",","(",")"),$text);
 $question = $_POST['editor1']; 

 $answer1 = extractString($question, '<strong>', '</strong>');

$sql="INSERT INTO strucquestions (part1,op1,op2,op3,op4,ans1,part2,op1a,op2a,op3a,op4a,ans2,part3,mode) VALUES ('$exploded[0]','$exploded[1]','$exploded[2]','$exploded[3]','$exploded[4]','$answer1','$exploded[5]','$exploded[6]','$exploded[7]','$exploded[8]','$exploded[9]','$answer2','$exploded[10]','$mode')";

echo "Successfully Inserted!";
$result = mysql_query($sql);
if (!$result) {
 die('Invalid query: ' . mysql_error());
}

function extractString($question, $start, $end) {
$question = " ".$question;
$ini = strpos($question, $start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($question, $end, $ini) - $ini;
return substr($question, $ini, $len);

echo "close";
        mysql_close($con);      

} 
?>
<button onclick="window.location.href='insertion.php'">Next</button><br>        <br>
但无法捕获第二个粗体文本并将其存储到数据库中的列中

<?php 
define('DB_HOST', 'localhost');
define('DB_NAME', 'palmdatas'); 
define('DB_USER','root');
define('DB_PASSWORD',''); 

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error()); 
$mode = $_POST['mode']; 
$question = $_POST['editor1']; 
$text = $question;

echo "\n";

$text = strip_tags($text);


function multiexplode ($delimiters,$string) {

$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return  $launch;
}

$exploded = multiexplode(array(",","(",")"),$text);
 $question = $_POST['editor1']; 

 $answer1 = extractString($question, '<strong>', '</strong>');

$sql="INSERT INTO strucquestions (part1,op1,op2,op3,op4,ans1,part2,op1a,op2a,op3a,op4a,ans2,part3,mode) VALUES ('$exploded[0]','$exploded[1]','$exploded[2]','$exploded[3]','$exploded[4]','$answer1','$exploded[5]','$exploded[6]','$exploded[7]','$exploded[8]','$exploded[9]','$answer2','$exploded[10]','$mode')";

echo "Successfully Inserted!";
$result = mysql_query($sql);
if (!$result) {
 die('Invalid query: ' . mysql_error());
}

function extractString($question, $start, $end) {
$question = " ".$question;
$ini = strpos($question, $start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($question, $end, $ini) - $ini;
return substr($question, $ini, $len);

echo "close";
        mysql_close($con);      

} 
?>
<button onclick="window.location.href='insertion.php'">Next</button><br>        <br>

您似乎想看看:

搜索模式中给定的正则表达式的所有匹配项,并按标志指定的顺序将它们放入匹配项中

这可能比使用
strpos
business更优雅,因为当使用它时,必须循环直到输入字符串结束