1. php 正則表達式如何添加URL參數 ,並把&替換成amp;
preg_replace('/(&|\\?)pagesize=[^&]+/', '', $_SERVER['REQUEST_URI']) str_replace 或replace 或preg_replace 用正則是比較笨的辦法
2. PHP 正則表達式如何替換URL參數
用正則是比較笨的辦法,但也給你提供一下了:
function getpage(){
//你可以把獲取當前page的代碼放在函數里
return 123;
}
$str = 'index.php?main_page=index&cPath=55&pagesize=48';
$ptn = '/&pagesize=(\d+)/';
$pagenum = getpage();
$rep = '&pagesize='.$pagenum;
echo $str; // 輸出:index.php?main_page=index&cPath=55&pagesize=48
preg_replace($ptn,$rep,$str);
echo $str; // 輸出:index.php?main_page=index&cPath=55&pagesize=123
另外多說一下,這種情況可以使用
http_build_query()
這個函數。
具體使用方法:
$u['main_page']=$_GET['main_page'];
$u['cPath']=$_GET['cPath'];
$u['pagesize']=getpage();
$url = 'index.php?'.http_build_query($u);
echo $url;
這個函數很好用,比你自己去匹配好。
3. php 正則表達式匹配到href的鏈接怎麼寫急!!!
$patten="/<ahref=['"]?([^'"]+).*?>/";
4. 用PHP正則將任何URL從文章中匹配出來,例如:http://.baidu.com/qct=17&pn=0&tn=ikask&rn=12&word
`I shall have my supper in another room,' I said. `Have you no place you call a parlour?'
`Parlour!' he echoed sneeringly, `parlour! Nay, we've noa parlours. If yah nnut loike wer company, there's maister's; un' if yah nnut loike maister, there's us.
`Then I shall go upstairs!' I answered; `show me a chamber.' I put my basin on a tray, and went myself to fetch some more milk. With great grumblings, the fellow rose, and preceded me in my ascent: we mounted to the garrets; he opening a door, now and then, to look into the apartments we passed.
`Here's a rahm,' he said, at last, flinging back a cranky board on hinges. `It's weel eneugh tuh ate a few porridge in. They's a pack o' corn i' t' corner, thear, meeterly clane; if yah're feared uh muckying yer grand silk cloes, spread yer hankerchir o' t' top on't.'
The `rahm' was a kind of lumber-hole smelling strong of malt and grain; various sacks of which articles were piled around, leaving a wide, bare space in the middle.
`Why, man!' I exclaimed, facing him angrily,coach outlet, `this is not a place to sleep in. I wish to see my bedroom.
`Bed-rume!' he repeated, in a tone of mockery. `Yah's see all t' bed-rumes thear is--yon's mine.'
He pointed into the second garret, only differing from the first in being more naked about the walls, and having a large, low, curtainless bed, with an indigo-coloured quilt at one end.
`What do I want with yours?' I retorted. `I suppose Mr Heathcliff does not lodge at the top of the house, does he?'
`Oh! it's Maister Hathecliff's yah're wenting!' cried he, as if making a new discovery. `Couldn't ye uh said soa, at onst? un then, Aw mud uh telled ye, baht all this wark,christian louboutin uk, ut that's just one yah cannut sea--he alIas keeps it locked, un nob'dy iver mells on't but hisseln.'
`You've a nice house, Joseph,' I could not refrain from observing, `and pleasant inmates; and I think the concentrated essence of all the madness in the world took up its abode in my brain the day I linked my fate with theirs! However, that is not to the present purpose--there are other rooms. For heaven's sake be quick, and let me settle somewhere!'
He made no reply to this adjuration; only plodding doggedly down the wooden steps, and halting before an apartment which, from that halt and the superior quality of its furniture, I conjectured to be the best one. There was a carpet: a good one, but the pattern was obliterated by st; a fireplace hung with cut paper, dropping to pieces; a handsome oak bedstead with ample crimson curtains of rather expensive material and modern make; but they had evidently experienced rough usage: the valances hung in festoons, wrenched from their rings, and the iron rod supporting them was bent in an arc on one side, causing the drapery to trail upon the floor. The chairs were also damaged, many of them severely; and deep indentations deformed the panels of the walls. I was endeavouring to gather resolution for entering and taking possession, when my fool of a guide announced, `This here is t' maister's.' My supper by this time was cold, my appetite gone,clarks shoes, and my patience exhausted. I insisted on being provided instantly with a place of refuge,clarks shoes uk, and means of repose.
5. 求PHP 的正則表達式 大全
匹配中文字元的正則表達式: [\u4e00-\u9fa5] 評註:匹配中文還真是個頭疼的事,有了這個表達式就好辦了 匹配雙位元組字元(包括漢字在內):[^\x00-\xff] 評註:可以用來計算字元串的長度(一個雙位元組字元長度計2,ASCII字元計1) 匹配空白行的正則表達式:\n\s*\r 評註:可以用來刪除空白行 匹配HTML標記的正則表達式:<(\S*?)[^>]*>.*?</\1>|<.*? /> 評註:網上流傳的版本太糟糕,上面這個也僅僅能匹配部分,對於復雜的嵌套標記依舊無能為 匹配首尾空白字元的正則表達式:^\s*|\s*$ 評註:可以用來刪除行首行尾的空白字元(包括空格、製表符、換頁符等等),非常有用的表達式 匹配Email地址的正則表達式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* 評註:表單驗證時很實用 匹配網址URL的正則表達式:[a-zA-z]+://[^\s]* 評註:網上流傳的版本功能很有限,上面這個基本可以滿足需求 匹配帳號是否合法(字母開頭,允許5-16位元組,允許字母數字下劃線):^[a-zA-Z][a-zA-Z0-9_]{4,15}$ 評註:表單驗證時很實用 匹配國內電話號碼:\d{3}-\d{8}|\d{4}-\d{7} 評註:匹配形式如 0511-4405222 或 021-87888822 匹配騰訊QQ號:[1-9][0-9]{4,} 評註:騰訊QQ號從10000開始 匹配中國郵政編碼:[1-9]\d{5}(?!\d) 評註:中國郵政編碼為6位數字 匹配身份證:\d{15}|\d{18} 評註:中國的身份證為15位或18位 匹配ip地址:\d+\.\d+\.\d+\.\d+ 評註:提取ip地址時有用 匹配特定數字: ^[1-9]\d*$ //匹配正整數 ^-[1-9]\d*$ //匹配負整數 ^-?[1-9]\d*$ //匹配整數 ^[1-9]\d*|0$ //匹配非負整數(正整數 + 0) ^-[1-9]\d*|0$ //匹配非正整數(負整數 + 0) ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //匹配正浮點數 ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //匹配負浮點數 ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //匹配浮點數 ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //匹配非負浮點數(正浮點數 + 0) ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //匹配非正浮點數(負浮點數 + 0) 評註:處理大量數據時有用,具體應用時注意修正 匹配特定字元串: ^[A-Za-z]+$ //匹配由26個英文字母組成的字元串 ^[A-Z]+$ //匹配由26個英文字母的大寫組成的字元串 ^[a-z]+$ //匹配由26個英文字母的小寫組成的字元串 ^[A-Za-z0-9]+$ //匹配由數字和26個英文字母組成的字元串 ^\w+$ //匹配由數字、26個英文字母或者下劃線組成的字元串 /http:\/\/(.*)\//i //匹配外部鏈接地址
滿意請採納
6. 怎麼用php正則獲得a標簽內的文字啊
php中正則匹配只要使用這兩個函數:
preg_match_all
preg_match
這里使用preg_match_all,代碼如下:
$subject='<ahref="xxx.php">abc測試</a>';//假設這是需要匹配的字元串
$pattern='/<ahref="[^"]*"[^>]*>(.*)</a>/';//這是匹配的正則表達式
preg_match_all($pattern,$subject,$matches);//開始匹配,該函數會把匹配結果放入$matches數組中
echo"<pre>";
print_r($matches);
/**
結果是:
Array
(
[0]=>Array
(
[0]=>abc測試
)
[1]=>Array
(
[0]=>abc測試
)
)
*/
7. PHP 正則驗證URL網址格式是否有效
PHP中的ereg()函數常用於驗證URL地址格式是否正確。此函數返回布爾值,用於指示驗證結果。下面是一個簡單的函數示例,用於檢查URL的有效性:
function CheckUrl($C_url){
if (!ereg("^http://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $C_url))
{
return false;
}
return true;
}
這個函數接收一個URL作為參數,通過正則表達式進行驗證。如果URL不符合規則,函數返回false;反之,則返回true。正則表達式定義了URL的基本結構,確保其符合標准格式。
例如,正則表達式"^http://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$"可以解析出http或https開頭的URL,其中[_a-zA-Z0-9-]+表示以字母、數字或破折號開頭的字元串,(.[_a-zA-Z0-9-]+)*則表示可能存在的子域名部分。
利用ereg()函數進行URL驗證是一種簡單有效的方法。然而,需要注意的是,ereg()函數在PHP7中已被棄用,應考慮使用preg_match()等替代方法。preg_match()同樣基於正則表達式,但在性能和功能上更為強大。
總之,通過正則表達式驗證URL格式是確保數據完整性的重要步驟,特別是在處理用戶輸入時。正確的URL驗證能夠幫助防止潛在的安全威脅,並確保應用程序的正常運行。
8. php如何正則匹配出帶問號的域名來php如何正則匹配出帶問號的域名來源
PHP-如何在PHP中使用正則表達式匹配URL中的域名
馬鞭php//從URL獲取主機名
preg_match(/^(http://)?(【^/])/i,,$matches);
$host=$matches[2];
//從主機名中獲取最後兩段
preg_match(/[^./].[^./]$/,$host,$matches);
回聲;
馬鞭month=$month中的$php_self是鏈接地址,這里給出的是一個變數來代替冗長的字元串,比如說www.phpfans.net,問號後面的year、month傳的參數,並分別給他們賦值為$y-lnk、$month。添加該鏈接出錯是語法錯誤!將雙引號去掉即可。
mysql中?號是什麼?
問號表示稍後將被replace的參數。使用參數化查詢比將參數直接embedded查詢更安全。
SQLServer調用這個參數化查詢,而Oracle調用它綁定variables。
用法因您執行查詢的語言而異。
這里是一個如何使用PHP的例子。
假設$mysqli是一個資料庫連接,而people是一個有4列的表。