0
問題はPHPに関連しています。私は変数に$ textといくつかの開始位置と終了位置を記述したテキストを持っています。特定の位置にいくつかの部分文字列を注入する方法。問題は、特定の位置にテキストを置くと、インデックスの位置が変化し、次のサブストリングを適切な場所に配置することが困難になることです。助けて。前もって感謝します。文字列を置換できません
function previewTxt($text,$topicid, $sectionid)
{
$dbConn = new DBConnUtil();
$queryString = "SELECT * from inline_topic_xref where TOPIC_ID=$topicid and SECTION_ID=$sectionid";
$result = $dbConn->run_query($queryString);
$newtext=$text;
$count=0;
while($row = $result->fetch_object())
{
$newtext = replace($newtext, "<a href='#'>" ,$row->REF_TEXT_START);
$newtext = replace($newtext, "</a>" ,$row->REF_TEXT_END);
}
return $newtext;
}
function replace($org_text,$str_rep, $position)
{
$length=strlen($org_text);
$temp1=substr($org_text,0,$position);
$temp2=substr($org_text,$position,$length);
$replaced =$temp1.$str_rep.$temp2;
return $replaced;
}
であるあなたが達成したいものの多くより具体的な例を与えることができますか? – Ronald
私はいくつかの特定の位置に ''と ''を長いテキストで注入する必要があります。その位置が記憶される。しかし、私がを置くと、文字列の長さが変わり、またはを他の位置に置くのは難しいです... – agnichakra