在php中如何打印粗体字,php – 如何捕获并将第二个粗体文本存储到数据库中?...

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

$example = ‘She went to the store to (buy,buys,bought,buying) some snacks when she (sees,see,saw,look) the accident.’;

管理将整个字符串存储到数据库中并将它们存储到相应的列中,并能够捕获第一个粗体文本并将其存储到数据库中.

但是无法捕获并将第二个粗体文本存储到数据库的列中.

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, '', '');

$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);

}

?>

Next

解决方法:

Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by flags.

这可能比使用strpos业务更优雅,因为在使用它时你必须循环直到你到达输入字符串的末尾.

标签:php,mysql

来源: https://codeday.me/bug/20190711/1434188.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值