我想找到并替换字符串start和end的一部分。 例如:
case $COMMAND in
start )
echo "Configuring OpenAM.."
cp /artifacts/openam.war /opt/tomcat/webapps/openam.war
cat /opt/openam-install.properties
/opt/tomcat/bin/startup.sh
sleep 20
ls -lart
cd /artifacts/configurator
unzip configurator.zip
java -jar openam-configurator-tool-13.5.0.jar --acceptLicense --file /opt/openam-install.properties
echo "Configuration Complete."
tail -f /opt/tomcat/logs/catalina.out
;;
成为:
<LAT>43.654209136963</LATS>
<LONGS>-0.59365832805634</LONGS>
<LAT>44.362339019775</LATE>
谢谢你的嗨
答案 0 :(得分:1)
似乎结尾标记始终是正确的标记,基于此,我们只需将结束标记替换为结束标记,即:
$xml = <<< LOB
<LAT>43.654209136963</LATS>
<LONGS>-0.59365832805634</LONGS>
<LAT>44.362339019775</LATE>
LOB;
$xml = preg_replace('%<(.*?)>(.*?)</(.*?)>%m', '<$3>$2</$3>', $xml);