php

matching a word to end of string with strpos

Solution: strpos turned out to be the most efficient. Can be done with substr but that creates a temporary substring. Can also be done with regex, but slower than strpos and does not always produce the right answer if the word contains meta-characters (see Ayman Hourieh comment). Chosen answer: if(strlen($str) - strlen($key) == strrpo...

How to delete photos that haven't been accessed for more than 5 days ?

I'm trying to create a cron job which will automatically delete .jpg files from a particular folder that haven't been accessed for more than 5 days. Running the cron job is not a problem, but how do I go about writing the script which will take care of the deletion? ...

Need a regular expression to parse a text body

Hi guys, I need a regular expression to parse a body of text. Basically assume this that we have text files and each of which contains random text but within the text there would be lines in the following formats - basically they are a format for denoting flight legs. eg: 13FEB2009 BDR7402 1000 UUBB 1020 UUWW FLT This line of text i...

slow php command line performance - is this normal or do I have an install problem?

I have a simple PHP app that prints 'hello world'. When I run it from the command line it takes 6 seconds. Is this normal? It seems to take 1 seconds before "hello world" prints, then 5 seconds after. I am running PHP version 5.2.12 on Windows Server 2008 R2. Could this be an install issue, or is it typical? I did a manual install ...

Perl & PHP project requirement

Hi all, I have learned Perl and PHP.So I want to do simple real time project in this by that I can improve my knowledge in Perl and PHP. Can anyone suggest me any requirements. Thanks in Advance ...

remove duplicate values from a multidimensional arrays in php

hi this is my array , i need to remove duplicating values , please hekp me out Array ( [0] => Array ( [0] => * garfield calicut Address: tanil nadu chennai0696955666 About Company: re stored. [1] => 0.0004 [2] => 0 ) [1] => Array ( [0] => * gamut Address: ashok puram calicut9865326921 About Company: Y...

How to insert the last id from a table into another table in MySQL?

I want to take the id of the most recent item in a database, increment it by one and insert that new id in to another table. I tried: $select = mysql_query("SELECT id FROM tableName ORDER BY id DESC"); while ($return = mysql_fetch_assoc($select)) { $id = $return['id']; $newId = $id++; } mysql_query("INSERT INTO anotherTable (...

How to run wget from php so that output gets displayed in the browser window?

How to run wget from php so that output gets displayed in the browser window? ...

Double associative array or indexed + associative array

I have an array apple color: red price: 2 orange color: orange price: 3 banana color: yellow price: 2 When I get input, let's say green apple how do I check if it exists in the array and display its data (if it exists). ...

remove row on click on specific td of that row by jquery

i have an table <table class="oldService"> <thead> <th>name</th> <th>age</th> <th>action</th> </thead> <tbody> <?php foreach($array as $k=>$v){ ?> <tr> <td><?php echo $k[name] ?></td> <td><?php echo $k[age]?></td> <td id="<?ph...

How to convert Msword file into a text file and storing it in Mysql - php joomla

Hey i want to convert MsWord doc file into text file - any code sample. And then i want to store it to in database MySql - any code. And also how to retrieve it in a same format tht was in Msword file using php joomla ...

php mysql search

Hello, My code contain SELECT * FROM newchap WHERE company LIKE '%$company%' OR Category LIKE '%$cat%' It works perfectly however, when the field $company contain empty, it return all result in MYSQL. How to prevent it? ...

PHP: friend classes and ungreedy caller function/class

Is there any way to get the caller function with something else than debug_backtrace()? I'm looking for a less greedy way to simulate scopes like friend or internal. Let's say I have a class A and a class B. Until now, I've been using debug_backtrace(), which is too greedy (IMHO). I thought of something like this: <?php class A...

Regex to slice filename contain string and numerical

hi, can anybody help me solve this : i got $filename= "index 198.php"; i use this and failed preg_match(" [a-zA-Z0-9]", $filename, $output); what kind of regex pattern i have to use so the $output array will be consist a number only value. ...

Why is $b "b" in this logic when echoing out ${$b}

I'd have expected ${$b} to be 'a' but it is 'b', why is this the case? $a = "b"; $b = "a"; Sorry again I forgot to put ${$b} produces "b" ...

How to iterate loop inside a string searching for any word aftera fixed keyword?

Suppose I have a sting as "PHP Paddy,PHP Pranav,PHP Parth", now i have a count as 3,now how should I iterate loop in the string aiming on string after "PHP " to display the all the names? Alright This is the string "BEGIN IF (NEW.name != OLD.name) THEN INSERT INTO jos_menuaudit set menuid=OLD.id, oldvalue = OLD.name, newvalue = NEW.name...

how to change type of value in an php array and sorting it..is it possible ?

hi, i got problem with my code and hopefully someone able to figure it out. The main purpose is to sort array based on its value (then reindex its numerical key). i got this sample of filename : $filename = array("index 198.php", "index 192.php", "index 144.php", "index 2.php", "index 1.php", "index 100.php", "index 111.php"); ...

Recursion through a directory tree in PHP

I have a set of folders that has a depth of at least 4 or 5 levels. I'm looking to recurse through the directory tree as deep as it goes, and iterate over every file. I've gotten the code to go down into the first sets of subdirectories, but no deeper, and I'm not sure why. Any ideas? $count = 0; $dir = "/Applications/MAMP/htdocs/site.c...

Why could wget not work with PHP's exec function?

My script tries to exec() wget but seems to fail (though, no error raises up). What could be the problem? Should I tune PHP somehow? I just installed Apache and PHP on Ubuntu... ...

How to extract substrings with PHP

PHP beginner's question. I need to keep image paths as following in the database for the admin backend. ../../../../assets/images/subfolder/myimage.jpg However I need image paths as follows for the front-end. assets/images/subfolder/myimage.jpg What is the best way to change this by PHP? I thought about substr(), but I am wonderi...