Я пытаюсь заменить все '
на foot
слово и "
на inches
слово.
Мне также нужно удалить все вложенные двойные кавычки и одинарные кавычки в слове.
Окончательный вывод должен быть:
start Rica's 5-1/8 inches another 7 inches here Week 5 foot again 7 foot last clean again hello Mark's end
Ниже приведен мой быстрый пример кода - еще не работает.
<?php
$title = 'start Rica\'s 5-1/8" another 7" here ""Week" 5\' again 7\' last \'clean\' again \'hello\' Mark\'s end';
$inches = '"';
$foot = "'";
$inches_word = ' inches';
$foot_word = " foot";
//$pos = strpos($title, $foot);
$pos_inches = strpos($title, $inches);
// check if before the " or ' is a number
$check_number_inches = substr($title, $pos_inches - 1, 1);
if (is_numeric($check_number_inches)) {
// replace " to inches
$title = str_replace($inches, $inches_word, $title);
}
$pos_foot = strpos($title, $foot);
// check if before the " or ' is a number
$check_number_foot = substr($title, $pos_foot - 1, 1);
if (is_numeric($check_number_foot)) {
// replace " to inches
$title = str_replace($foot, $foot_word, $title);
}
echo $title;
?>
Заранее спасибо:)