Snippets: All Listings RSS

Filter listings...
{stwpreview url="http://stackoverflow.com/questions/5749415/search-for-a-string-or-part-of-string-in-php" link="no" divwrap="no"}

stackoverflow.com/questions/5749415/search-for-a-string-or-p...

I am doing a very small online store application in PHP. So I have an array of maps in PHP. I want to search for a string (a product) in the array. I looked at array_search in PHP and it seems that it only looks for exact match. Do you guys know a bett ...

Category:Snippets
Visited164
{stwpreview url="http://stackoverflow.com/questions/2109325/how-to-strip-all-spaces-out-of-a-string-in-php" link="no" divwrap="no"}

stackoverflow.com/questions/2109325/how-to-strip-all-spaces-...

This is a stackoverflow thread on this topic.

Category:Snippets
Visited169
{stwpreview url="http://stackoverflow.com/questions/1703320/remove-excess-whitespace-from-within-a-string" link="no" divwrap="no"}

stackoverflow.com/questions/1703320/remove-excess-whitespace...

I receive a string from a database query, then I remove all HTML tags, carriage returns and newlines before I put it in a CSV file. Only thing is, I can't find a way to remove the excess white space from between the strings.

What would be the b ...

Category:Snippets
Visited204
{stwpreview url="http://www.hashbangcode.com/blog/uk-postcode-validation-function-php" link="no" divwrap="no"}

www.hashbangcode.com/blog/uk-postcode-validation-function-ph...

Creating a function to validate UK postcodes would seem like a simple task, but there is a little more to it than checking the number of characters. In fact there are several different variants of UK postal codes, especially if you include BFPO and ove ...

Category:Snippets
Visited142
{stwpreview url="http://stackoverflow.com/questions/7454644/how-to-get-open-graph-protocol-of-a-webpage-by-php" link="no" divwrap="no"}

stackoverflow.com/questions/7454644/how-to-get-open-graph-pr...

PHP has a simple command to get meta tags of a webpage (get_meta_tags), but this only works for meta tags with name attributes. However, Open Graph Protocol is becoming more and more popular these days. What is the easiest way to get the values of opg ...

Category:Snippets
Visited140
{stwpreview url="http://www.codingforums.com/php/34709-preg_match-syntax.html" link="no" divwrap="no"}

www.codingforums.com/php/34709-preg_match-syntax.html

This thread shows you clearly how to use preg_match() and explains the different switches.

Category:preg_match()
Visited122
{stwpreview url="http://stackoverflow.com/questions/10201337/what-do-the-symbols-mean-in-preg-match" link="no" divwrap="no"}

stackoverflow.com/questions/10201337/what-do-the-symbols-mea...

I have this expression in a code snippet i borrowed offline. It forces the new users to have a password that not only requires upper+lower+numbers but they must be in that order! If i enter lower+upper+numbers, it fails!

if ...

Category:preg_match()
Visited134
{stwpreview url="http://stackoverflow.com/questions/10358300/preg-match-array-items-in-string" link="no" divwrap="no"}

stackoverflow.com/questions/10358300/preg-match-array-items-...

This is a stackoverflow thread on this topic.

Category:preg_match()
Visited105
{stwpreview url="http://stackoverflow.com/questions/6228581/how-to-search-array-of-string-in-another-string-in-php" link="no" divwrap="no"}

stackoverflow.com/questions/6228581/how-to-search-array-of-s...

Firstly, I want to inform that, what I need is the reverse of in_array PHP function.

I need to search all items of array in the string if any of them found, function will return true otherwise return false.

I need the fastest solution t ...

Category:Arrays
Visited124
{stwpreview url="http://stackoverflow.com/questions/555975/how-to-find-a-string-in-an-array-in-php" link="no" divwrap="no"}

stackoverflow.com/questions/555975/how-to-find-a-string-in-a...

This is a stackoverflow thread on this topic.

Category:Arrays
Visited123
{stwpreview url="http://stackoverflow.com/questions/10303705/php-check-first-second-third-char-in-array" link="no" divwrap="no"}

stackoverflow.com/questions/10303705/php-check-first-second-...

This is a stackoverflow thread on this topic.

Category:Arrays
Visited113
{stwpreview url="http://docstore.mik.ua/orelly/webprog/pcook/ch04_12.htm" link="no" divwrap="no"}

docstore.mik.ua/orelly/webprog/pcook/ch04_12.htm

TheProblem: You want to know if an array contains a certain value.

Category:Arrays
Visited130
{stwpreview url="http://stackoverflow.com/questions/5445668/checking-value-against-an-array-issue" link="no" divwrap="no"}

stackoverflow.com/questions/5445668/checking-value-against-a...

Basically what I have is a function that accepts a single string $name as a variable, then it goes through and checks that variable against values in an array. If the variable is found in the array is returns TRUE. This function is called from within a ...

Category:Arrays
Visited134
{stwpreview url="http://stackoverflow.com/questions/14177170/php-string-to-array-check-spelling-back-to-string-preserving-special-charact" link="no" divwrap="no"}

stackoverflow.com/questions/14177170/php-string-to-array-che...

I'm working on a custom spell checker (and learning as I go) that needs to do the following upon form submission:

  1. Convert the string submitted from textarea into an array of words.
  2. Search for each word in the array in the mysql ...

    Category:Arrays
    Visited130