strpos

Problem with Strpos In PHP

Hey Folks 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; ...

SQL Server: any equivalent of strpos()?

I'm dealing with an annoying database where one field contains what really should be stored two separate fields. So the column is stored something like "The first string~@~The second string", where "~@~" is the delimiter. (Again, I didn't design this, I'm just trying to fix it.) I want a query to move this into two columns, that would...

Removing specific characters from a string in php

Hi 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 ...

My mistake with "strpos" function? php

hello, I am trying to get strpos to search string variable $string for the phrase "test" and if it doesn't contain test another variable $change is redefined as $string2 (where $change has been defined previously) if (strpos($string, 'test') == false) { $change = $string2; break; } but unfortunately it doesn't work. Is there a ...

Odd strpos behavior

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...

PHP: Using strpos() to find only the needle

I am using strpos() to find the needle in the haystack. But, I want it to only find the needle with the same string length. E.g.: $mystring = '123/abc'; $findme = 'abc'; $pos = strpos($mystring, $findme); // THIS IS FINE $mystring = '123/abcdefghijk'; $findme = 'abc'; $pos = strpos($mystring, $findme); // THIS IS NOT FINE So, I...

Performance wise String Matching

I've a generic DB query function that runs the following checks every time an SQL query is issued: if (preg_match('~^(?:UPDATE|DELETE)~i', $query) === 1) if (preg_match('~^(?:UPDATE|DELETE)~iS', $query) === 1) if ((stripos($query, 'UPDATE') === 0) || (stripos($query, 'DELETE') === 0)) I know that a simple strpos() call is way faster ...

Sort search results from MySQL by the position of the search query in the string using PHP

I want my search results to be in order of string position from smallest to greatest. For example, searching for "banana" returns: Babyfood, plums, bananas and rice, strained Bananas, dehydrated, or banana powder Bananas, raw Bread, banana, prepared from recipe, made with margarine CAMPBELL Soup Company, V8 SPLASH Juice Drinks, St...

In PHP, strpos() fails to find double quote ('"') in string

echo 'Tok: '.$tok.' Strpos: '.strpos($tok, "\"").' length: '.strlen($tok).'<br>'; And this: echo 'Tok: '.$tok.' Strpos: '.strpos($tok, '"').' length: '.strlen($tok).'<br>'; Result in the following output: Tok: "fresh Strpos: length: 11 Strpos is failing completely to find the double quote, it returns false (I checked with strpos(...

php 5 strpos() difference between returning 0 and false?

if(strpos("http://www.example.com","http://www.")==0){ // do work} I'd expect this to resolve as true, which it does. But what happens when I do if(strpos("abcdefghijklmnop","http://www.")==0){// do work} This also passes on php 5 because as far as I can work out the strpos returns false which translates as 0. Is this correct thin...

PHP - Checking whether a string exists in an entire array?

Hi all, Basic array question: $string = "The quick brown cat"; $check1 = "apple"; $check2 = "ball"; $check3 = "cat"; if ( (stripos($string, $check1) === false) || (stripos($string, $check2) === false) || (stripos($string, $check3) === false) ) { echo "Fail"; } How do I condense the above using an array ($check[])? ...

Insert string between two markers

I have a requirement to insert a string between two markers. Initially I get a sting (from a file stored on the server) between #DATA# and #END# using: function getStringBetweenStrings($string,$start,$end){ $startsAt=strpos($string,$start)+strlen($start); $endsAt=strpos($string,$end, $startsAt); return substr($string,$startsAt,$...

What exactly does this PHP code do?

Alright, my friend gave me this code for requesting headers and comparing them to what the header should be. It works perfectly, but I'm not sure why. Here is the code: $headers = apache_request_headers(); $customheader = "Header: 7ddb6ffab28bb675215a7d6e31cfc759"; foreach ($headers as $header => $value) { // 1 $cu...

str_replace() and strpos() for arrays?

I'm working with an array of data that I've changed the names of some array keys, but I want the data to stay the same basically... Basically I want to be able to keep the data that's in the array stored in the DB, but I want to update the array key names associated with it. Previously the array would have looked like this: $var_opts['s...

PHP strpos preg_match

Hi, I want to copy a substring of a string using PHP. The regex for the first pattern is /\d\|\d\w0:/ The regex for the second pattern is: /\d\w\w\d+:\s-\s:/ Is it possible combining preg_match with strpos to get the exact positions from start to end and then copy it with substr( $string, $firstPos,$secPos ) ? ...

Tagging phrases in paragragh

I am using PHP and I am looking to create links within my text to other sections of the site so for example: I fell into the media industry aged 30, when David Mansfield, now on the board of Ingenious Media, gave me my first break at Thames TV. From there, I worked at the (now-defunct) Sunday Correspondent and IPC, before joining TDI, w...

scrape email addresses

fff.html is an email with email addresses in it some have href mailto links and some don't, i want to scrape them and output them into the following format [email protected],[email protected],[email protected] I have a simple scraper to get the ones that are href linked but something is wierd <?php $url = "fff.html"; $raw = f...

PHP String Contains with Shadowbox

I'm using shadowbox to display media based on URLs from a database. Some of the media are images and some are websites and some are flash movies I wish to check if an image contains "http://" meaning it's a website (all images and flvs start with "media/"), and if it does contain http:// then I wish to display it at a different size. ...

Facebook fql case insensitive version of strpos

Hi! What is the case insensitive version of strpos(field', 'Phrase') in facebook query language? ...

strpos in Emacs Lisp

Is there a native Emacs Lisp function that behaves like strpos() in PHP? It should return the position of first occurrence of the given string in current buffer. Function search-forward is nice, but it modifies the character position. ...