php

how to assing values into global array inside a function? (php)

I have a function that searches for a string inside a text file. I want to use the same function to assign all lines to an array in case I am going to replace that string. So I will read the input file only once. I have the search function working but I do not know how to deal with the array thing. the code is something like that (I ma...

Calculating shortest path between two "locations" via php from a mysql db

Hi, I'm trying to figure out the best method of getting/displaying the shortest distance between multiple locations. To best explain this think of it as a map and use the following below. All of the distances and paths from each location would be already put in a mysql database. Locations(Letter -> Locations it can reach. and distance/...

Problem in creating thumbnail of png image !!

Hi, I have used the following php function to create thumbnail image. function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) { $dir = opendir( $pathToImages ); while (false !== ($fname = readdir( $dir ))) { $info = pathinfo($pathToImages . $fname); if ( strtolower($info['extension']) == 'jpg' || strtolowe...

Mysterious "_gaq is not defined" error... _gaq isn't even referenced anywhere on the page!

EDIT: This question is solved, but I can't accept my own answer just yet. Howdy! So I've got a PHP/CodeIgniter webapp. I've got some custom Ajax-based tracking code inserted into my page - however obviously, for testing purposes, I don't want this code to fire when I'm running the site locally on my development computer. In order to a...

SQL 'Like' causing duplicate content

Hey all I am using MySQL and the 'like' query in order to find pages. I need to be able to do things this way, but this means that these pages will be the same: www.mysite.com/blog/hello-world www.mysite.com/blog/hello-worl They both work, and bring up the same page. How (possibly using .htaccess?) can I get around this problem? :\ ...

Searching MySQL fields with similar fieldnames

Hi. New to mysql and php, so forgive any obvious stupidity, please! One of mysql tables has category fields, indexed from a table of categories. Each of the categories is named category_1, category_2, category_3, etc. I'm assuming that can't I use a wildcard to search these categories, like: 'SELECT * FROM products_table WHERE cat...

Cross-Site Scripting Phishing Through Frames

how we can protect a website from "Cross-Site Scripting Phishing Through Frames" by php.. thanks ...

PHP time() in script/function vs $var=time();

I have a globalish variable which is $VARcurrenttime = time(); then I normally call that variable when computing anything with that timestamp (which is a lot). Someone suggested to me that using time() instead of the variable would be somewhat faster. I don't really know but could someone advise me on whether I would bother changing this...

flash and jquery or html5 audio?

What is the best way to construct a audio player that can communicate with the jquery on my site? Can I have flash send jquery commands when a song is finished playing? Does html5 audio support a onSongEnd or similar function? Songs on my site are a series of links that trigger jquery to reload a flash audio player with the appropriat...

use php scandir($dir) and get only images!

Is there any way to get only images (jpeg,png&gif) while using: $dir = '/tmp'; $files1 = scandir($dir); ...

Formatting PHP time() from mysql table

I'm creating comments stored in a MySQL database. I'm logging the php time function time() as the comment is posted. That way it's displaying a message such as... "comment... posted 4 seconds ago" and if I refresh the page 2 minutes later it'd display "comment... posted 2 minutes ago" Here's how I am entering time() into the database ...

Avoiding Bad PHP Coding

There is a lot of books and tutorials about php that are completely different from each other. How can I choose the right way? Is the only way is test with xdebug or phpUnit or benchmark? ...

Can you solve this in brief code??

there are 10 variables. say $var1, $var2, $var3, $var4,....$var10 and a $count variable. what I am looking for is if all variables are set then $count = 10+1 or if 9 variables only set then $count=9+1 or if 8 variables only set then $count=8+1 and so on last up to 1 variable(for one variable is set then $count = 1+1). I know do this w...

how to create dynamic row in php and html

I need to create a table in runtime by using php and html,the table should look like:- image1 image2 image3 name1 name2 name3 --------------------------------- image4 image5 image6 name4 name5 name6 total 2 rows,each row containing 3 data,each data again containing 2 rows,one is a imag...

Parse PHP Session in Javascript

Hey everyone, I have recently gone into extending my site using node.js and have come to realisation I need a session handler for my PHP sessions. Now everything was cool and dandy and node.js reads the php sessions and can propogate it's own session with the php ones. I am using database sessions so the session data gets saved into a f...

Make a multidimensional array through loop!

How can i make an array like below through a loop? The text will generated from database! $listofimages = array( array( 'titre' => 'PHP', 'texte' => 'PHP (sigle de PHP: Hypertext Preprocessor), est un langage de scripts (...)', 'image' => './images/php.gif' ), array( 'titre' => ...

Regex: matching all improper tag attributes

For an example input of: <a href="abc" something=b foo="bar" baz=cool> I am trying to match: something=b baz=cool However, everything I end up with will only match the first one (something=b), even when using preg_match_all. The regular expression I am using is: <\w+.*?(\w+=[^"|^'|^>]).*?> Or: <\w+ # Word starting with < .*? #...

PHP - Calling .php file from command line produces no output

I have a simple cmd.php page to run commands I enter using shell_exec () and show the output. PHP is running as CGI Entering "php -v" and most commands just show "Content-type: text/html" and then the current page's HTML source. However, calling PHP with an invalid parameter (/usr/bin/php -z) shows PHPs usage: Usage: php [-q] [-h] [-s...

Create an HTML table like this one

Hello guys, i posted a question a while ago and i got my answer but now i kind of want a followup to this problem so i have a table like the one in the picture but i want to add total to each row or in fact a group how can i do that. This is the php code to create this table how to edit it to add the total. $sql = mysql_query( "SELECT...

Simply include the script or a function?

What is the best way? include the script write the script as function in for example functions.php, include the functions.php and call function thanks ...