簡體   English   中英

如何在php中替換以下模式

[英]How to replace the following pattern in php

我只想替換以下字符串中以(%...)開頭的值(可能是十六進制)。

$string = 'hello@example.com%0A%0a%0B%0C%0F%0f%AA';

預期的輸出是hello@example.com。

我怎樣才能做到這一點? 我正在使用preg_replace但使用正則表達式模式失敗。

如果您需要從這樣的字符串中提取電子郵件,那么還有一種不使用正則表達式的解決方案:

$string = substr($string, 0, strpos($string, '%'));

嘗試

$string = preg_replace('/%[a-fA-F0-9]{2}/', '', $string);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM