php

How to implement scoped function in PHP?

function parent($key) { function son() { global $key; } } I want to achieve this: son can access the $key of parent As it's quite a simple function,I don't want to change parent into a class OK,I've been told that function are global anyway.Is there a way for son to get $key of parent then? ...

Create a php menu that highlights current tab

So I have a menu in a php file that looks like this (This is the whole file. I'm totally new to PHP.) menu.php: <li id="current"><a href="#"><span>Home</span></a></li> <li><a href="http://blog.me.net/"&gt;&lt;span&gt;Blog&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; <li><a href="http://www.me.net/R"&gt;&lt;span&gt;Results&lt;/span&gt;&lt;/a&gt;...

How to get past day from current time in php

I want to calculate whats the date 20 yrs back from current time in php.How can do that.I am not able to figure this out in a proper manner. Scenario is: I am having a column dob in mysql. Now i want to retrieve all the users who age is more than 20yrs and less than 25 yrs. I am using doctrine orm Edit Its working fine but giving a w...

Script to control own browser

So I'm trying to debug my website... basically what I need to do is write a script that will periodically follow a link on my page, but I need to see the result in my browser which is why I need it to happen in the browser. I want it to click on the same link every few seconds without any human interaction. The resulting page each time w...

PHP: How do I convert a regular expression to an example match?

Hi, I have a regular expression for matching URIs: eg: preg_match("/^my\/uri\//i", "my/uri/whatever"); which I use for routing: eg: "http://www.mywebsite.com/my/uri/page.html" will match the above (with the protocol/host removed of course) now I was wondering if there was any way to evaluate the regular expression into the most gener...

How to add attribute to first P tag using PHP regular expression?

WordPress spits posts in this format: <h2>Some header</h> <p>First paragraph of the post</p> <p>Second paragraph of the post</p> etc. To get my cool styling on the first paragraph (it's one of those things that looks good only sparingly) I need to hook into the get_posts function to filter its output with a preg_replace. The goal is ...

What is wrong with this simple jQuery slideUp and slideDown?

Hello, I want to display the image actual view when the mouse is over the thumb sized image. But when the mouse is placed over the first image it appears and then disappears, not the case with the second and following images. It works perfectly fine in IE, but not in FF or Chrome. $file - runs displays all the files in a directory $i...

Is there a PHP IDE that can handle Magento's code base?

Magento has a large code base (6000+ php files), uses a complex autoloading logic, and has a lot of configuration in XML. I'm looking for an IDE that can get it's little brain around this code base - show me where a function is declared, where it's called, etc. Is there any IDE that can handle this beast? EDIT - Adding examples Here...

PHP: How do I strip all regex?

How do strip all regex special characters from a string? eg: I have "/^bla\/bla\/bla\//i" which I want to be: "bla/bla/bla/" ...

Get text after needle?

If i had the following text in a string: <h4>Tom</h4> <p>One Paragraph</p> <p>Two Paragraph</p> What code would i need to parse on that string to get an output like this (if i didnt know what was inside the <h4> tag? <p>One Paragraph</p> <p>two Paragraph</p> Thanks! ...

How to hack IPB to update twitter account with every new topic?

I have been given a task to enable existing Invision Power Board Forum to update Twitter account whenever a new topic is created. I should probably mention that I've already done this to other custom CMS software of the same client. And because it was custom built software it was possible to hack the code. In this particular task that ...

PHP file-handling; Special characters in folder names

I am using rename() to move a file from one folder to another with php. It works fine with folders which don't have the swedish å ä ö characters involved. Is there any way around this? (except for changing the folder names to something without special chars) The website is entirely in utf-8 format... ...

PHP - To echo or not to echo?

What is more efficient and/or what is better practice. To echo the html or the have many open and close php tags? Obviously for big areas of html it is sensible to open and close the php tags. What about when dealing with something like generating XML... should you open and close the PHP tags with a single echo for each piece of data or...

PHP function not working as expected

<?php function getPosts($showposts,$tags, $thumb_key="thumb_300x166", $thumb_class, $thumb_width="300", $thumb_height="166") { $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('tag=$tags&showposts=$showposts'); while ($wp_query->have_posts()) { $...

How to separate returned values in php?

I am using a php function that will return 2 arrays.below is my function function imserv($id){ $xml=simplexml_load_file("feed.xml"); $images=$xml->xpath('//IMAGE'); $services=$xml->xpath('//SERVICES'); return array ($images,$services); } i use the below code to get results from the services block $services=imgserv('5874'); foreac...

List items by category

Hello I have 3 tables: category doesnt matter item2cat: itemID|catID item: id|name|desc I want to list the items that are in the given category, but I don't know how to do it in a simple way. (With PHP and MySQL) I need this table-structure because I want multiple categories to one item. ...

send email with url image

i am including a path to an image like this: $msg.='<img src="http://my.test.ca/images/show.jpg" width="75" height="75" />' in my sendmail function. the path works and the image is in the specified folder. here is what happens to the image src when i get the email: http://my.test.ca/images/sh%20w.jpg it sorts of breaks the image. ...

Un-define constants with define/apc_define_constants in PHP

I'm using constants for output messages in different languages. For example, if a user chooses "English", a file with this constant would be required: define('welcomeMessage','Welcome!'); If she chooses "Spanish": define('welcomeMessage','Bien Venidos!'); etc etc... The problem occurs when a user iterates through languages. I can...

Changing or eliminating Header & Footer in TCPDF

AddPage() in tcpdf automatically calls Header and Footer. How do I eliminate/override this? ...

delete all values from an array while keeping keys intact.

Do I really have to do this to reset an array ?? foreach ($array as $i => $value) { unset($array[$i]); } EDIT: this one makes more sense, as the previous one is equivalent to $array=array(); foreach ($array as $i => $value) { $array[$i]=NULL; } ...