选择字符串的一部分 [英] Selecting a part of a string
本文介绍了选择字符串的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串存储在变量 say
I have a string stored in variable say
$input = 999 success: id:10.123/AVC13231 | ark:/asf4523/2425fsaf
我只想选择字符串10.123/AVC13231"的一部分
I want to select only a part of a string "10.123/AVC13231"
说我想实现这个:
$output = 10.123/XXXXXXXX ;
并且不应选择其他部分 $input 甚至 id: 部分
and no other part $input should be selected even the id: part
值 10.123 是常数,值 AVC13231 会动态变化.
The value 10.123 is constant and the value AVC13231 changes dynamically.
我如何才能实现上述目标?
How can i achieve the above?
推荐答案
这是一个解决方案.
$input = "999 success: id:10.123/AVC13231 | ark:/asf4523/2425fsaf";
$pos1 = strpos($input, 'id:')+3; // Remove 'id:'
$pos2 = strpos($input, '|')-1; // Remove space before pipe
$output = substr($input, $pos1, ($pos2 - $pos1));
这篇关于选择字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文