strpos

which is the fast process strpos()/stripos() or preg_match() in php

﹥>﹥吖頭↗ 提交于 2019-12-18 17:08:42
问题 I just want to known which one will be fast of strpos()/stripos() or preg_match() functions in php. 回答1: I found this blog that has run some testes regarding your question, the result was: strpos() is 3-16 times faster than preg_match() stripos() is 2-30 times slower than strpos() stripos() is 20-100 percent faster than preg_match() with the caseless modifier "//i" using a regular expression in preg_match() is not faster than using a long string using the utf8 modifier "//u" in preg_match()

Odd strpos behavior

跟風遠走 提交于 2019-12-18 09:22:42
问题 This is my code: <?php $url = "http://www.uhasselt.be/collegeroosters/2009_2010_298_5_10.html"; $headers = get_headers($url, 1); print_r($headers); $contloc = $headers["Content-Location"]; echo "Content-Location: " . $contloc . "\n"; $soft404test = strpos($contloc, "http://www.uhasselt.be/404b.htm") ? true : false; var_dump($soft404test); ?> This is its output: Array ( [0] => HTTP/1.1 200 OK [Content-Length] => 2030 [Content-Type] => text/html [Content-Location] => http://www.uhasselt.be/404b

Problem with Strpos In PHP

坚强是说给别人听的谎言 提交于 2019-12-18 08:57:17
问题 I'm writing a simple function and for some reason(probably a simple one) it's not working for me and I was wondering if you guys could help me out. function check_value($postID) { $ID = $postID; $cookie = $_COOKIE['list_of_IDS']; $position = strpos($cookie,$ID); echo 'ID:'.$ID.'-Cookie:'.$cookie; if ($position !== false) { echo "ID is in the cookie"; } } In trying to figure out what the problem was I put that echo line above the If Statement there to make sure there actually is stuff in the

Fnd specific place in string and get data from it

别说谁变了你拦得住时间么 提交于 2019-12-16 18:03:43
问题 I have string with multiple image tags in it. Like this <img src="/files/028ou2p5g/blogs/9d66329f4/5844644f69fe7-64.jpg"> I want to find FIRST such tag, and get image name from it 5844644f69fe7-64.jpg How can be this done in PHP asuming there is a lot of other text and tags in string ? 回答1: You should use like what @moopet suggested. This is the code, but please give credit to @moopet. $str = '<img src="/files/028ou2p5g/blogs/9d66329f4/5844644f69fe7-64.jpg">'; $doc = new DOMDocument(); $doc-

How to check multiple words exist in the string? (returns true it there is at least one of those words)

末鹿安然 提交于 2019-12-13 02:01:17
问题 I have a string like this: $str = "it is a test"; I want to check it for these words: it , test . I want to it returns true if there is at least one of those words in the string. Here is what I did: (though it does not work) $keywords = array ('it', 'test'); if(strpos($str, $keywords) !== false){ echo 'true';} else echo 'false'; How can I do that? 回答1: simply checking using preg_match , you can add many different words in the pattern, just use a separator | in between words $str = "it is a

PHP Tidy完美的XHTML纠错&过滤

我的梦境 提交于 2019-12-12 19:12:44
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 输入和输出 输入和输出应该说是很多网站的基本功能。用户输入数据,网站输出数据供其他人浏览。 拿目前流行的Blog为例,这里的输入输出就是作者编辑文章后生成博客文章页面供他人阅读。 这里有一个问题,即用户输入通常是不受控制的,它可能包含不正确的格式亦或者含有有安全隐患的代码;而最终网站输出的内容却必须是正确的HTML代码。这就需要对用户输入的内容进行纠错和过滤。 永远不要相信用户的输入 你可能会说:现在到处都是所见即所得的编辑器(WYSIWYG), FCKeditor 、 TinyMCE ...你可能会举出一大堆。是的,它们都可以自动生成标准的XHTML代码,但是作为web开发人员,你肯定听过"永远不要相信用户递交的数据"。 因此对用户输入数据进行纠错和过滤是必需的。 需要更好的纠错和过滤 目前为止我还没见过有让我满意的相关实现,能接触到的通常都是效率低下、效果不太理想,有这样那样的明显缺陷。举个比较知名的例子: WordPress 是一种使用非常广泛的blog系统,操作简单功能强大且有丰富的插件支持,但是它集成的TinyMCE和后台一堆有些自作聪明的纠错过滤代码却令人相当头痛,对半角字符的强制替换,过于保守的替换规则等等.....导致像贴一段代码让它正确显示这种需求都很难做到。 这里顺便抱怨一下

Getting the file name from a text file after string matching - PHP

爷,独闯天下 提交于 2019-12-12 05:49:44
问题 I have a log file ( log.txt ) in the form: ========================================= March 01 2050 13:05:00 log v.2.6 General Option: [default] log_options.xml ========================================= Loaded options from xml file: '/the/path/of/log_options.xml' printPDF started PDF export PDF file created:'/path/of/file.1.pdf' postProcessingDocument started INDD file removed:'/path/of/file.1.indd' Error opening document: '/path/of/some/filesomething.indd':Error: file doesnt exist or no

I cannot get strpos to work with newline

徘徊边缘 提交于 2019-12-11 19:04:14
问题 I am very new to php and cannot find out how to fix this. I have a form and want to pass some string to it and have it checked with another file. It is working fine if all the strings are on the same line but as soon as I put in multiple lines of string, it will fail. I have a php file with the following code: <?php echo "<center><form method='post' enctype='multipart/form-data'>"; echo "<b></b><textarea name='texttofind' cols='80' rows='10'></textarea><br>"; echo "<input name='submit' type=

Removing specific characters from a string in php

我的未来我决定 提交于 2019-12-11 10:56:16
问题 How can I check a string in php for specific characters such as '#' or '\'? I don't really want to use replace, just return true or false. Thanks 回答1: use the function strstr http://us2.php.net/manual/en/function.strstr.php Returns part of haystack string from the first occurrence of needle to the end of haystack Note: If you only want to determine if a particular needle occurs within haystack , use the faster and less memory intensive function strpos() instead. 回答2: You can use the strpos

Get a substring of a string

谁说胖子不能爱 提交于 2019-12-11 02:22:45
问题 I've been trying to get a substring of a string that contains around 40 lines of text. The string is something like this but with aprox. 30 more lines: Username: example Password: pswd Code: 890382 Key: 9082 type: 1 Website: https://example.com/example Email: example@example.com I need to get the value of, for example, Code which will be 890382 , but I can't seem to do it. Each field like Code or Key is unique in the string. The best (if possible) would be to read the values and store them in