Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Function To Check For Multiple Instances Of A String In An Array?


I need to check if there are more than one of the same string in an array. Does anyone know of a function?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Check Array For A String
I am trying to set up a blacklist for a service I'm making. My current objective is to call up a .txt file which contains one domain name per line. I then take the user's input from a HTTP post and check to see if it contains the domain name. Here is my current non working script:

//take user's input (example: http://www.somesite.com/files/photo.jpg)
$filename = $HTTP_POST_VARS['filename'];

//load blacklist in case of abuse
$blacklist= file('blacklist.txt');

//check submitted image against blacklisted domains
foreach($blacklist as $site){

if (strstr($filename,$site) !== FALSE) {
echo "<div><h3>This site is blacklisted</h3></div>";
exit();}}

This doesn't seem to work at all. I think it has something to do with the variable types, but I am too unfamiliar with this for Google to be a viable solution.

Check For Multiple Occurances In An Array.
I am checking an array for existence of a value, but I want to see how many times it exists in the array.

Is there a quick function to do this or must I use a loop and step through? I looked through the manual and did not see any array functions that would do this, but I may have misunderstood one of them. Which has happened before.

I was using this before I realized I had multiple occurences in the array. PHP Code:

Function Will Check To See If One String Exists In Anther
I am looking for a function that will check to see if one string exists in anther. here is an example.

$stringa = "new";
$stringb = "Show new replies to you posts"

if ($stringa is in $stringb){
   do something here
}

any ideas?

Please Help: Prevent Multiple Instances
How can I prevent a script from running when a previous instance of
the script had already been triggered and the script is running in the
background already?
So, even when a script is startet several times (eg. by several
website visitors) I want only one script-instance running on the
server. Subsequent instances should be exited (or prevented) right
away to keep the server load as low as possible.

However, when no instance of the script is currently running (eg.
after a server shut-down), triggering the script should make it run -
but again: only one instance should be running at all times. Further
script calls, as said above, should then not be allowed.

PHP Multiple Instances / Sessions Question
I am currently running 2 instances of a web application on the same
server.
one of them has address http://www.justanexample.com/prod and the other
has an address of http://www.justanexample.com/ipeer_demo. By logging
into the demo with the guest passwords, the address becomes
http://www.justanexample.com/ipeer_...on=Student.home.
I can get into the production instance by simply changing the base url
to http://www.justanexample.com/prod/i...on=Student.home and
hitting enter. I'm sure there are quite a few solutions to this, but
what do you think is the most secure way of overcomming this problem?

Return All Instances Of A String Within A Page...
I'm looking to do this, but is it possible?:

A page to be downloaded via file_get_contents which has stuff similar to
the following in :

<a href="file.php?name=Widget1">Widget1</a><br>
<a href="file.php?name=Widget2">Widget2</a><br>
<a href="file.php?name=Widget3">Widget3</a><br>
etc.

I would like to be able to create an array which contains all the strings
between <a href="file.php?name=Widget1"> and </a><br> (The link text)

so
<a href="file.php?name=Widget1">Widget1</a><br> => Widget1

So that $linktext[0] = Widget1, [1] = Widget2 etc.

Is this possible, if so, how?
I've looked at preg_match_all, but can't see how to output multiple matches
of text *between* two strings to an array.....

Multiple Instances Of Body Tags In A Page Due To The Includes Each Having A Set.
This is not the way it's supposed to be, is it... ok then for me just
to remove the body tags from the include files, it'll all work ok? I
don't know php and I'm working with a webmaster who, I suspect,
doesn't know it too well either.

Multiple Php.ini Instances - Configuration Tree Errors (PHPIniDir)
We're running multiple vhosts in an apache-2.x configuration for which
we would like to provide separate php.ini files (for different
reasons).

At the moment, we're unable to do this - the error I'm seeing is:

Starting httpd: Syntax error on line 87 of
/etc/httpd/conf/vhost.conf.admin:
Only first PHPINIDir directive honored per configuration tree -
subsequent ones ignored
[FAILED]

So my question here is in a couple of parts. One, is it even possible
to do what I'm trying to do... and what is a "configuration tree" -
does that refer to the entire instance of the apache server itself. Is
it possible to have more than one "configuration tree"s.

Multiple Array Into Function
This is the code i am using to populate my $values array. I believe the way I am trying to populate this array is wrong.

$values = array();

$query = 'Select * from round_info natural join tee where player_id = 1 limit 10'
$result = mysql_query($query);
if (!$result){
die ("Could not query the database: <br />" . mysql_error());
}

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$values[] = $row['gross_score'] => $row['course_rating'] => $row['course_slope'];
}

$handicap_index[] = handicap_differential($values);

The function handicap_differential is also wrong i believe. I am passing in an array I want it to do some math with that array values and pass me back another array. Then with that array complete the last foreach statement and give me a handicap back.....

Array Of Instances Inside Constructor
keep an array of all
of its instances? This was my first and obvious first shot...

class A
{
function A()
{
static $a = array() ;
$this->array =& $a ;

$this->array[] =& $this ;
}
}

But, if I make changes to the instance contents (not included above)
they are lost when I eventually try to use the array of references.

Multiple Function Calls Or Character Array Concat?
I'd like to know sth about the costs of a function call in php
and the handling of character arrays (init size, enlargement steps of
allocated memory, technique on enlargement -> full copy or virtual
array spread in chunks over mem).
The reason of my question is the following:

// many function calls with smaller char arrays and less concats
echo('wkjksdbjvsdnklvsDVL'.$a.'vfaadf');
echo('wkjksdbdnklvsDVL'.$b.'vfaadf');
echo('wkjksdbjvslvsDVL'.$c.'vdf');
echo('wkjksdbnklvsDVL'.$d.'vfdf');

// single function call with bigger char array and more concat steps
echo('wkjksdbjvsdnklvsDVL'.$a.'vfaadf'
.'wkjksdbdnklvsDVL'.$b.'vfaadf'
.'wkjksdbjvslvsDVL'.$c.'vdf'
.'wkjksdbnklvsDVL'.$d.'vfdf');

So this also arouses the question, wether a function argument that is
passed as literal or expression will be passed by reference or by value?
And does it make any difference, that echo is in fact a language
construct and not a function, though the function-like syntax will be
accepted? http://www.faqts.com/knowledge_base...ml/aid/1/fid/40
says the only difference is, that a boolean return value will be set
by a 'print' function call, while echo does not. But again no details on
implementation of function calls, character arrays or arrays in general.

I tried php.net to find out on these not unimportant implementational
details but unfortunately found nocthing.

How To Check For Multiple @'s
We are trying to prevent spammers from mass mailing their list while
using our contact us script. We have a few security measures in place
but would also like to add a "check for more than 1 @'s in the to:, cc:
and bcc: fields. Can anyone point us to some code or turotials for
doing this?

How To Check If Multiple Of 2?
I am creating a tournament script and need to have total matches as a multiple of 2 (2, 4, 8, 16, 32... ). How can i check the number to see if it's ok.

example
$matchesNum = 38;//obviously this is not a multiple

How would I check that number to make sure it was 32 or 64...

Check If Variable Is Multiple Of TWO
Is there another fast way (withOUT to call a PHP function), to do this? It is to know if a variable (into a loop) is a multiple of two. PHP Code:

Check A String
Hey everyone, how would I check a string for having only numbers and having 4 integers exactly?

String Check
I want to check if a string contains only alphabetical and/or numerical characters. I think the solution is eregi, but i am not an expert on regular expressions..

Check If A String Contains Something Other Than
How do I check if a string contains something other than E.g

If $string has "" in it, it will be rejected. But if it has "hello"  in it that will be okay.

Handling Multiple Check Boxes
I have a PHP generated page which displays X many records. Each record has
a checkbox preceding it. The user checks several checkboxes, and hits a
delete button. All the corresponding records will be deleted.

But I'm running into difficulty...

Right now the NAME property of each check box is the primary key of the
corresponding record. Hence if I know which checkboxes are checked, I
simply use DELETE using the NAME value.

Generally speaking, how do I get the server side to see which check boxes
were checked?

The check box names may not be sequential, if any records have been deleted
previously, and the first check box might be a number greater than 0.

Is there an easy mechanism to do this? Some kind of built in cnotrol array
allowing me to loop over every check box that was on the form submitted?

I could store the last and first checkbox number in a hidden input, then
loop starting/ending at those values, but that may loop over a lot of
controls that do not exist.

Multiple Variables Eregi Check.....
This is an easy one I think but I just can't do it for some reson - I want to check more than one variable on the same line, not just address, but can't work out the syntax to do this...

ie. So this code........

$crack=eregi("(to:)|(from:)|(cc:)|(bcc:)",$address);

does this........

$crack=eregi("(to:)|(from:)|(cc:)|(bcc:)",$address and another variable);

I want it so that if any of the variables meet the criteria set in the eregi function then $crack will be true (or 1).

How To Check The Beginning Of A String
I was wondering if it is possible to check if the beginning of a string starts with a certain other way. For example:: searching http://slashdot.org for http:// should return true, but searching shttp:// for http:// should return false.

Check String Contents: Can Be Used As Var?
is there anyway to check if a string could be used a variable name. So
return false if the first character isn't a letter or if it contains
spaces etc.

I started writing a function that would do a load of tests because I
couldn't see any easier way of doing it:

<?
function is_valid_handle($str) {
// determines if the string provided can be used as a handle
// such as a php variable or html/css class
if (strlen($str) > 255)) return false;
if (strpos($str,' ')) return false;
// incomplete, needs more tests
return true;
}
?>

but as soon as i realised i would have to use range() to check all the
characters were valid and all that i decided there must be an easier
way. Do you guys know of one or am I just going to have to write it myself?

It was about then I had a great idea maybe if you use the variable
variable syntax you can see if it will return false but unfortunately it
does this:

<?
$foo= &#395;very @#bad variable name'
$$foo = 'Hi!' // doesn't cause error
echo $$foo; // outputs Hi!
echo $5very @#bad variable name; // causes an error, obviously
?>

Seems PHP will quite happily let you store data in a variable of
whatever you like. I guess that's a nice feature. So...any ideas?

Check For A String Validation
I want to check if a string validates some of my rules. My string must consist only : letters from a to z and A to Z, all the digits 0-9 and these symbols - '@','_','.','!',':' and space.

The only thing i know is that a 'ereg' function must be used. I've seen so many examples but i can't get how exactly does ereg work. Another rule for the string is using cyrillic letters.

Check String Length
Is there a way to check a variables character count and also to strip out spaces so :

cheese bacon ham = cheesebaconham = 14 characters.. then some how assign the 14 to a variable also ?

Another Way To Check For Different Characters In String
Right now I find myself doing things like this:

if(strpos($uname,"`")!==false || strpos($uname,"~")!==false || strpos($uname,"@")!==false || strpos($uname,"$")!==false || strpos($uname,"%")!==false || strpos($uname,"^")!==false || strpos($uname,"&")!==false)
{}

This seems a bit silly; I want to check a single string for many different characters. Is there another way of doing this?

Check Whether A String Contains HTML Elements
I want to check whether a string  contains HTML elements. Is there is any function to check whether a string contains HTML elements.

How To Check String Input Format
I'm workign on a database where the user enters a document number and description.  I'd like to check that the document number matches a format (NNN-NNN) and that the description contains only spaces and alphabetical characters.  Is there a simple way to do this?  I'd guess for the num I break it into 3 parts and check for num, dash and num but I"m not even sure how to do that. 

Parse Part Of String (mid String Function ?)
Can someone tell me how to parse part of a string? I can use the following:

<?php
$text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url);
echo $text;
?>

to get this result:

"Your currently at /test.php "

I just want to get "test.php " without the dash. I also need to parse out
parts of other strings. I know how to use Mid(), Left(), and Right() in VB,
but no clue for PHP.

Check An Input String For Data Types
What's the best way to check to see if an input string is made of completely letters or completely numbers? I wrote this, but it doesn't seem to work. I'll follow it with an example. Code:

Check What Type (integer, String Etc) A Database Field Is
If i have a datebase field like so:

$username = $row['username']; //after SELECT and mysql_query etc.

how do i check what file type it is? i have tried using is_string to
check it but it returns all fields back as strings, even the ones i
know are integers. i would like something that would tell me the data
tyle (integer, varchar, text etc). are there any other ways or am i
doing this wrong?

Function To Check If A Site Is Down Or Not
I am looking for a function to check if a remote url is down (giving a 404) or running (giving a 200) but I can't find one. Does someone know such a function?

Login Check Function
I made the following function that checs if someone who loged on my site is enabled to view a certain page: PHP Code:

Function To Check Money Value
I am looking for a good function to check if a entered value is
a money value - meaning it's a decimal with no more then 2 digits after the point.

Check If A Function Has Been Called?
Is it possible to check if a function was called within a certain page? If so, how?

Sorting An Array Problem, (array/string Manipulation)
I have a function that I found on google, that goes through a directory and spits out a directory tree in an array, with arrays inside of arrays, and more and more arrays inside of arrays, depending on how many subdirectories are there.....

Here is a sample "directory tree" it spits out. My problem is wanting to be able to create a new array containing only the paths to all the subdirectories it finds from this array, so it is with array manipulation...

Not all paths are located in the topmost array's values, but some directories are within other subdirectories and so forth.. I'm stumped on how exactly to sort through this array, whether recursively or not to grab all the 'paths' in the array period. Code:

Is There A Function To Search A String Within Another String ?
for e.g, fnding the word "hello" in this string : "hello world"...

Function To Check If A File Exists Or Not?
Does anyone know if there is a function to check whether a file exists or not? Something like readfile(), but which DOESNT actually output the file. I'm trying to write an upload script, so something like this:

if (@readfile("$filename"))
{
echo "This file exists already";
}
else
{
echo "This file does not exist";
}

Anyone know?

How To Check If Variable Is An Array?
I'm using php 4.4.4. How do i check if a given variable is an array
or simply a scalar?

Check If Number Is In An Array
how can i check if a specified number is in an array e.g

number =5
searching in array (1,2,3,4,5)

I know how to do it for a mysql query, but I need to do it in PHP, anyone kno how i could do this. Also say I have several numbers I want to check are in the array, how would I do this.

Check Variable Value In Array
I'm wandering if there's a function in php which lets you check for a variable value in a preset array, and how you could check this (TRUE / FALSE) For example:

$variable = a;
$array = array("a","b","c");

How To Check If Array Is Empty?
I am using an array named $outdata, and just wish to know how to check if the array is empty.

I am using this method  if(empty($outdata)); i am not sure this is the right way to check if array is empty. Here is the code

$outdata=array();
$outdata[]="Hello";
$outdata[]="Welcome";

if(empty($outdata));
{
$outdata[]="You are not authorized";
}
else
{
do something...
}

Check If An Element Exist Within An Array
I thought there must be a simple function that checks if an element exist within an array. I can't find it anywhere... does anybody know?

Check If Array Holds Another Value In A For Loop
This is my code so far: PHP Code:

Check If Any Items In An Array (php) Is In A Table (mysql).
I want to check if any of the items in a PHP array exist in a MySQL
table. What is the best way to do this with making repeated calls to the
database for each item?

Actual application is:

I have an array (in PHP) of serial numbers of units about to be
shipped.I want to check the ship record (a table in a MySQL database) to check
if that serial number has been used before.

According to our quality policy we never reuse serial numbers, serial
numbers are unique. So prior to printing the packing slip I want to
warn the shipping guy/gal a serial number may be incorrect.

I could brute force it and increment through the "to be shipped array"
and check each item against the table. But that is, as I said brute
force, and I am having to be concerned with system speed lately.

Check Referer - Call To Unsupported Or Undefined Function Error()
I have a Fatal error: Call to unsupported or undefined function error() in line 24
Line 24 is: error("Unauthorized access to: $HTTP_REFERER"); What I'm doing wrong?

$referers = array('mydomain.com','www.mydomain.com');

function check_referer () {
global $REFERERS, $HTTP_REFERER;
if ($HTTP_REFERER != "")
while (list($val, $ref) = each($REFERERS))
if (preg_match("/^http://$ref/", $HTTP_REFERER))
return;
error("Unauthorized access to: $HTTP_REFERER");
exit; }
check_referer();

Getting Multiple Selection Into One String
I have a listbox with 5 options. I have set it up to be able to choise more than one option. What I need to know is how to get all the selection into the one string that is stored in the DB

It is easy to get the first selected option to post into the DB.

Multiple Replacements In String
I'm trying to figure how to make multiple replacements in a string before echoing the string out.

str_replace('Chris Drury', '<a href="/profile.php?playerid=23">Chris Drury</a>', $fullstory); The above code does what I need it to do but just for one player. I want to find a way to make it happen for about 30 players.

Is there a way to do this in PHP?

Passing Array Of Multidimensional Array To Function
How do I pass a part of a multidimensional array to a function. I have the following (in pseudo):

$arrays[m][n]; // filled with values
$chosen = 3;

function doSomething($array) {
 // do something with 1D array
}

This fails:

doSomething($arrays[$chosen]);

Can someone explain to me why? And how to do this right?

Replacing Multiple Characters In A String
I want to remove some characters from form input. Using this:

$comment = str_replace('example', 'Example', $comment);

works great, but how would I replace more than one charcter or string? Would it be done with an array? I knew how to with Perl, but I can't find the equivilent in PHP.

Also, for security purposes, would removing characters like ";<>&*~|#" from the form input be a good start in keeping my forms less open to sneaky coders? Maybe replacing those characters with the ISO character set numbers? This is for a guestbook-type page, so I feel that high security isn't that necessary for the file the input is being written to. I just don't want people to be able to screw around with other files via the form.

"Array To String Conversion" Error When Constructing A Multi-dimensional Array
I'm a bit stumped as I am getting a "Notice: Array to String
Conversion" error when trying to do something that on the surface
should be a very simple task - create an array, and write a set of
values to them based on data submitted from POST Fields.

Code below:

$_SESSION["increment"] = array();
$x = 0 // Counter - This will be
incremented

$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);

It keeps throwing out that error, and does not write any of the POST
Values to the array (the POST values are definitely getting sent, so
that is not the problem).

If I dump out the value of $_SESSION["increment"], I get "1A" ?!?

I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.


Copyright © 2005-08 www.BigResource.com, All rights reserved