php ignore special characters,PHP忽略第5个字符?(PHP ignore 5th character?)
PHP忽略第5個字符?(PHP ignore 5th character?)
我有一個簡單的PHP問題。
在我的PHP中 ,我有這個:
$variable = 'howareyou';
有可能以某種方式修改代碼,因此它只計算變量的第6個字符?
所以之后,當回聲
它會說怎么代替你怎么樣 。
我需要用數字過濾它,比如5號或6號 。 這可能嗎?
謝謝!
I have a simple php question.
in my php, I have this:
$variable = 'howareyou';
is it possible to somehow modify the code so it only counts up to 6th character of the variable?
so after, when echo'd
it would say howare instead of howareyou.
I need to filter it with a number, like 5th or 6th. Is this possible?
Thanks!
原文:https://stackoverflow.com/questions/5321237
更新時間:2019-12-05 11:40
最滿意答案
只需使用子串。
$variable = substr($variable, 0, 6)
語法是substr(string,start,length),并記住它們是零索引的。
Just use substring.
$variable = substr($variable, 0, 6)
The syntax is substr(string, start, length) and remember that these are zero indexed.
2011-03-16
相關問答
它錯過了最后一個值,因為如果找到+則只添加數字。 所以對于最后一個unparsedNumber你永遠不會輸入else if (c == '+')塊。 讓我建議一個更緊湊的解決方案: public int addFromString(string str)
{
string trimmed = str.Trim();
if (str.StartsWith("+") || str.EndsWith("+")) return 0; // invalid -> return immedia
...
你可以做line = line[1:]去掉第一個字符。 但是,如果你這樣做,你應該添加一個斷言,第一個字符確實是一個選項卡,以避免在沒有領先選項卡的情況下損壞數據。 有一個更容易的選擇,也可以處理其他幾種情況,如果要刪除的東西不存在,則不會中斷任何事情。 您可以使用line = line.strip()所有前導和尾隨空白。 或者,使用.lstrip()僅剝離前導空白,如果要保留其他空白并只刪除制表符,則可以將'\t'作為參數添加到任一方法調用中。 You could do line = line[
...
只需使用子串。 $variable = substr($variable, 0, 6)
語法是substr(string,start,length),并記住它們是零索引的。 Just use substring. $variable = substr($variable, 0, 6)
The syntax is substr(string, start, length) and remember that these are zero indexed.
^(?!(.)\1+$)[XO]{5}$
試試看。 https://regex101.com/r/uK9cD8/1 ^(?!(.)\1+$)[XO]{5}$
Try this.See demo. https://regex101.com/r/uK9cD8/1
這將做到這一點... ^\w\d\.(\d{3})\s(?:([YN])|\d)\s*(\d:\d{2})$
我對你的正則表達式做了一些其他的改變,因為我更容易根據你的數據重寫它,然后嘗試修改你的數據。 這將捕獲Y或N,否則它不會捕獲該組中的任何內容。 我也試圖用你的持續時間正則表達式更具體。 更新:這適用于您的新需求... ^\w\d\.(\w{3})\s(?:([YN])|\d|\s)\s*(\d:\d{2})$
你可以在這里看到它處理你的數據... http://regexr.com?3
...
你能嘗試使用str_replace嗎? $datetogoto = $_GET['datetogoto'];
$datetogoto = str_replace("-","", $datetogoto);
參考: http : //us1.php.net/str_replace 或者,如果你想獲得在查詢字符串中發送的任何日期格式,那么使用urlencode() header('Location: ../index.php?newsdate='.urlencode($datetogoto));
...
\字符是一個轉義字符。 你得到一個語法錯誤,因為\"是在String文字中放置一個"字符的轉義序列。 要在String文本中放置\ ,您需要使用\\ (第一個\轉義第二個\的特殊含義)。 所以一個語法正確的陳述是: String[] parts = "\u0041\u006e\u0064\u0072\u006f\u0069\u0064".split("\\");
但是這不會給你想要的,因為第一個參數不包含任何\字符。 (另外, split()方法需要一個正則表達式,而\不是一個有效的正則表達式
...
您可以在for循環中使用范圍功能: text = "Do you like green eggs and ham? I like them, Sam I am! Do you like green eggs and ham, Sam? Do you like them, Sam I am?"
transform = ''
for l in range(4, len(text), 5):
transform += text[l]
#remove spaces (as your examp
...
由于 - 字符串的長度為3或4,因此在-之后只能獲取3個字符。 這是代碼片段 LEFT(@a, CHARINDEX('-', @a) + 3) = LEFT(@b, CHARINDEX('-', @b) + 3)
Since the length of sub-string after - is either 3 or 4, you just only fetch 3 characters after -. Here is code snippet LEFT(@a, CHARINDEX('-',
...
使用此基于交替的正則表達式: \.:\d{3}|:(\d{3})
并抓住你所在比賽的第一組。 RegEx演示 Use this alternation based regex: \.:\d{3}|:(\d{3})
And grab captured group #1 for your matches. RegEx Demo
總結
以上是生活随笔為你收集整理的php ignore special characters,PHP忽略第5个字符?(PHP ignore 5th character?)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android音乐进度条设计代码,【An
- 下一篇: 现代软件工程系列 学生和老师都不容易