0

たとえば、文字列内の特殊文字の位置を決定する必要があります。

E77eF/74/VA の 6 と 9 の位置 (1 から数えて) には「/」があるので、それらを位置番号に変更する必要があります -> E77eF 6 74 9 VA

MSSQL では PATINDEX を使用できますが、これには php を使用する必要があります。0-9a-zA-Z 以外のすべてで機能するはずです

私はphp.netで見つけましたが、うまくいきませんstrpos()strrpos()とにかくそのようなことをしようとしますか?

4

2 に答える 2

1
<?php

$content = 'E77eF/74/VA';
//With this pattern you found everything except 0-9a-zA-Z
$pattern = "/[_a-z0-9-]/i";
$new_content = '';

for($i = 0; $i < strlen($content); $i++) {
    //if you found the 'special character' then replace with the position
    if(!preg_match($pattern, $content[$i])) {
        $new_content .= $i + 1;
    } else {    
        //if there is no 'special character' then use the character
        $new_content .= $content[$i];
    }   
}   

print_r($new_content);

?>

出力:

E77eF6749VA

于 2015-07-04T17:55:57.007 に答える