PHP - Warning: Strpos() [function.strpos]: Empty Delimiter.
Hi Guys
I've been trying to work on my OS Commerce site, but for some reason I'm getting this error on the main index.php page. Welcome Guest! Would you like to log yourself in? Or would you prefer to create an account? Feel free to click any of the links below to access the main categories. Warning: strpos() [function.strpos]: Empty delimiter. in /var/www/vhosts/XXXXXX.co.uk/httpdocs/shop/index.php on line 319 319 shows this: if (isset($cPath) && strpos('_', $cPath)) { Any ideas where this error comes from? Similar TutorialsHi, I'll be honest don't have a clue what I am doing but a friend asked me to look into her site, she gets the following error at the top of this page http://www.morairaluxuryvillas.com/rentals/villalist.php Warning: strpos() [function.strpos]: Offset not contained in string in /home/morairal/public_html/rentals/villalist.php on line 85 the code on the line 85 is: $secondfstemp = strpos($block1, ".", $firstfs); I am more than willing to look into but don't know where to start - anyone have any ideas? Thanks for your time:-) Hi All, I am trying to create a PHP code that will run a form, however i keep getting the error message Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in D:\xampp\htdocs\HFCC\Scripts\mailprocess.php on line 55 Invalid email address entered. Go Back and try again attached is the complete copy of the code i am using, i have an email text box and label with the id 'email' also my method is POST and my action is Scripts/mailprocess.php. Please let me know if you need any additional details. Any help will be much appreciated. Thanks Please help me with this code. It keep appear in my website. "Warning: preg_match() [function.preg-match]: No ending delimiter '.' found in /home/kengsite/public_html/wp-content/plugins/statpress/statpress.php on line 1184" And this is how the line look like. if (!preg_match(".ico$", $urlRequested)) { return ''; } How do I do two strpos conditions? here is kinda what I have.... if (strpos($val,'Sparring') && ($val,'Ecas') { } Hi Im having a problem finding the posistion of a div tag I tried this piece of code $fpos= strpos($snip, "<div id=\"footer\">") Then this piece $fpos= strpos($snip, "<div id="footer">") The $snip is the entire html document I thought maybe the \ might be causeing problem but without it Then i tried this any suggestions guys Thanks James Hey guys I need some help I did a quick search and couldn't find my problem so I hope I didn't miss it. Anyways, I've got a bit of code in which when a specific website is visited, it generates a log. This is to track the number of times the website gets visited and from where. I know this sounds like a counter, but it's different. I'm having a problem though, because right now, I can't get it to generate for ONLY the website entered. It generates for EVERY website instead of just the specific one. Right now this is what I have.. if (strpos($_url, "MY_SPECIFIC_WEBSITE") //URL { I've tried adding to it to fix it, but I'm obviously still learning PHP and am sick of strugglnig. If anyone could please help I would appreciate it so much. Hello, Am a little puzzled on how to effectively determine if a character exists in a string. I am trying to come to grips with the function strpos but its a little confusing. If am searching for an underscore in a string and want to echo yes if the string contains an underscore, would the code below be right? Would it be right to exclude booleans TRUE and FALSE Example 1 Code: [Select] <?php $string = "Hello_World"; if(strpos($string, "_")) { echo "yes"; } OR do I have to include the booleans TRUE/FALSE Example 2 Code: [Select] <?php $string = "Hello_World"; if(strpos($string, "_") == TRUE) { echo "yes"; } I have a string like this: Code: [Select] $data = "<a href="">Arbitrary characters. Bla bla bla</a><p>123456789</p><p>$10,100</p><p>01/02/2010</p><p>01/02/2011</p>"; What I am trying to accomplish is to extract the number between the first <p> tags as well as the date between the last <p> tags. I can extract the first number just fine by doing this: Code: [Select] $opening_p = strpos($data, '<p>'); $opening_p += 3; $closing_p = strpos($data, '</p>'); $length = $closing_p - $opening_p; // The length of the number changes, so I need to know the current length $first_number = substr($data, $opening_p, $length); However, no matter what I do, the position for the fourth <p> comes out to be the same as the first <p> In other words, this produces exactly the same number for the <p> Code: [Select] $opening_fourth_p = strpos($data, '<p>', 4); $opening_fourth_p += 3; So even with the offset in strpos, the position is exactly the same for both "extractions". So to conclude, both of these returns the same value: Code: [Select] $opening_p = strpos($data, '<p>'); $opening_fourth_p = strpos($data, '<p>', 4); Is there something I miss? This will be an easy one for you guys...
One of the fields in a MySQL database is a varchar() that was populated using a checkbox method and can contain more than one response. in this case i have blue, yellow, green and want to check if the field contains blue before echoing the statement to the screen. How would i use strpos in this case? ive tried a few thigns and get syntax error. The below of course works if the field ONLY contains blue. if (($row['colorsyoulike']) =='blue') { echo "<tr>"; echo "<td>Blue is an available Color!</td>"; } thanks. Great alliteration in the title. *Ahem* Anyway I have this code that I use for my chat system, And I'm making a command system. However when I send the command, It picks it up as a command etc. but it is so stubborn it will not realise it. I'm guessing it's my human error again like usual but take a look, See if you can help me (Please note the filea() function is for debugging it's telling me where the code (by printing to file) is taking me as the way I'm using it I can't just use echo or print whatever and see the results on a page) if(substr($text, 0, 2)=="::"){ //the command trigger is :: filea("Picked up the start of the command"); $subt1=substr($text, 2); //seperate the command trigger, In my case :: to execute the command. filea("Just checking the string... ".$subt1); $comms=array('ban', 'mute', 'cls', 'sysm', 'unmute'); $match=false; foreach($comms as $comm){ $commtest2=strpos($subt1, $comm); if($comtest2!=false){ //I also tried ==true first with no success $match=true; $command=$comm; break; } } filea("Ran command checker"); if($match==false){ filea("Command not found match=".$match); exit; //Exit out if there were no matching commands. } When I run this command: ::mute test this is the log that gets given to me, As you can see from the code this is what I put in there. Code: [Select] 3:07 AM) Logged in //this isn't in the code... (3:07 AM) Set text (3:07 AM) finding stats of person gergy008 (3:07 AM) Not muted. Continue... (3:07 AM) Has powers //up to here. But you don't need this. :) (3:07 AM) Picked up the start of the command (3:07 AM) Just checking the string... mute test (3:07 AM) Ran command checker (3:07 AM) Command not found match= As you can see I'm like -.- it's finding that the command is mute but it won't find mute in that string. It's dumb. Can someone help me find what the heck is wrong with this? I will be truely greatful Thanks! Which is most efficient for finding a string within a string? Eregi or strpos? Currently im using Eregi to check a string again an array of blocked words and retrun true if one is present. But it seems i can do it also with strpos... so which is best function to use ? Hi all I am grabbing the _SERVER['REQUEST_URI'] and trying to compare it but this doesnt work $currpage = $_SERVER['REQUEST_URI'];//when i echo this i get ' / ' $home = '/'; //but this doesnt work if(strpos($currpage, $home)){echo 'test works';} PS It will work if i use if($currpage == $home){echo 'test2';} Any ideas? Thanks, Magnetica Hi I have a page pulling information from mysql table, it lists names, I have these inside a hyperlink so that where there is a website listed for that record then the user can click on the name and move to their website. Only thing is that what happens if there is not a website for that record. I wanted a script so that if there is a website address listed then it prints the hyperlink but where there is not a website address listed that only the name is printed and it is not a hyperlink. I understand that the strpos can be used for this I have written a script but it is only printing out the name even when there is a website address in the row. What is wrong? PHP Version 5.3.4 Any help very much appreciated Code: [Select] <?php $website = $org_website; $link = 'http'; $weblink = strpos ($website,$link); if ($weblink === !false) { echo "<a href=\"$org_website;\"> FindOrganiserName($org_id); \"> FindOrganiserName($org_website); </a>"; } else { echo FindOrganiserName($org_id); } ?> Code: [Select] $mystring = "|Signature"; $findme = '|'; $pos = strpos($mystring, $findme); echo $pos; echo's 0 supposed to echo out 1....? why not work thanks How can I enable it to check for Code: [Select] | using strpos? If $allcat=10 and $cat_id in my While loop is 1,2,4,5,6,7,8,10,12 Why does $pos = strpos($allcat,$cat_id); select 1 and 10? My script: Code: [Select] $ssql="SELECT * FROM adcat WHERE disabled='0' ORDER BY name ASC"; $sresult=mysql_query($ssql); while($srows = mysql_fetch_array($sresult)){ $cat_id = $srows['id']; $cat_name = $srows['name']; $link=$srows['clinkname']; $tot_ads = $srows['ads']; $cat_desc = $srows['description']; $rrows=$srows['div']; $catcol1=$srows['catcol1']; $catcol2=$srows['catcol2']; $catcol3=$srows['catcol3']; $catcol3a=$srows['catcol3a']; $divsub=$srows['divsub']; ///////////////// $pos = strpos($allcat,$cat_id); if($pos === false) { $selected[$cat_id]=''; }else { $selected[$cat_id]='selected="selected"'; } //////////////// echo '<option '.$selected[$cat_id].'>'.$cat_name.'</option>'; } ?> </select> Hy ya'll! I've been trying to programatically read a string, but with no success. Code: [Select] function get_between($input, $start, $end) { $substr = substr($input, strlen($start)+strpos($input, $start), (strlen($input) - strpos($input, $end))*(-1)); return $substr; } $string = 'open -greetings hello -bye seeya'; echo get_between($string, '-greetings ', ' -bye'); // Output: hello echo get_between($string, '-greetings ', ' -'); // Outputs nothing echo get_between($string, '-greetings ', ' '); // Outputs nothing } It turns out that I don't know if "-bye" will always follow the value of "-greetings", so I can't call everything in between like the first way even tough it works fine in this example. Given that those values will always be a single word, I can use a whitespace as a delimiter to the right, but for some reason it won't return anything whatsoever, not even an error code. Any ideas how to get it done? Txs a bunch! I find it a bit buggy that strpos returns false instead of -1.
The equivalent C implementation returns -1:
int strpos(char s[], char t[]) { int i, j, k; for (i = 0; s[i] != '\0'; i++) { for (j=i, k=0; t[k]!='\0' && s[j]==t[k]; j++, k++) ; if (k > 0 && t[k] == '\0') return i; } return -1; }The problem with returning false is that false can also evaluate to 0 which can also happen to be the first index of a match. Therefore, you have a hard to find bug. I know that you can use the identity operator to check for falseness: ===. But wouldn't it be a better design for the function to just return -1? Hi all, I've gotten some great help from people here in the past, and just return with one question: I've got a field in a DB that contains a string of hyphen-separated values: "Accordion-Bass(Upright)-Bass-Bassoon" I pull that string through a MySQL query, which ends up in the array key "$currentuser['Skills']" Based on that string, I want to check a series of check-boxes to see whether a particular string is present in the array key, and, if so, check the corresponding box: Code: [Select] <input name="M-Accordian" type="checkbox" value="Accordion-" <?PHP if (strpos($currentuser['Skills'],"Accordion-") == "true") echo "checked=\"checked\"";?>/>Accordion <br /> <input name="M-UpBass" type="checkbox" value="Bass (Upright)-" <?PHP if (strpos($currentuser['Skills'],"Bass (Upright)-") == "true") echo "checked=\"checked\"";?> />Bass (upright) <br /> <input name="M-Bass" type="checkbox" value="Bass-" <?PHP if (strpos($currentuser['Skills'],"Bass") == "true") echo "checked=\"checked\"";?> />Bass <br /> <input name="M-Bassoon" type="checkbox" value="Bassoon-" <?PHP if (strpos($currentuser['Skills'],"Bassoon-") == "true") echo "checked=\"checked\"";?> />Bassoon <br /> However, whenever I load the form, despite the presence of the strings, only the first checkbox will ever correctly load checked. Can "strpos" only be invoked on a variable once, after which it can no longer be used? Thanks, and please let me know if you need more info to work from! Howver Hey guys, OK, heres what I would like to do. On my form, I have 50+ variables and not all of them require a response. If inserted, they insert a blank in the DB, instead of NULL. First, does this even matter? If it does, how can I create a function that checks the var to see if its empty, and if empty $var = NULL; Thanks |