php5

Regular expression negative replace?

I need to get "yomomedia.com" if the HTTP_HOST is [ANY].yomomedia.com except in the cases where it is "dev.yomomedia.com" else it should return dev.yomomedia.com echo preg_replace("/^([EVERYTHING-OTHER-THAN-DEV])\./Ui","",$_SERVER['SERVER_NAME']) Just tried the following with no success: echo preg_replace("/^(?!dev)\./Ui",'','www.yom...

Why is mime_content_type() deprecated in PHP?

I'm just curious to know why mime_content_type() is now considered deprecated. This method for determining the mime type is much easier than the replacement Fileinfo functionality. ...

Delete records from database with an Ajax request

hi all friends I am using php / mysql and protype.js to delete record from a table. The problem is that the record in the database is not deleted. index.php: <a href="javascript: deleteId('<?php echo $studentVo->id?>')">Delete</a></td> Script is function deleteId(id) { alert("ID : "+id); new Ajax.Request(...

Php Merging Arrays on Date

I have two arrays which I'm trying to merge based on the date of them. Here is what the arrays look like: $a[0][0] = '11/15/08'; $a[0][1] = '50'; $a[1][0] = '11/20/08'; $a[1][1] = '75'; $a[2][0] = '01/04/09'; $a[2][1] = '23'; $a[3][0] = '01/09/09'; $a[3][1] = '92'; and $b[0][0] = '01/04/09'; $b[0][1] = '30'; $b[1][0] = '01/05/09'; $...

Does PHP have an equivalent to Python's list comprehension syntax?

Python has syntactically sweet list comprehensions: S = [x**2 for x in range(10)] print S; [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] In PHP I would need to do some looping: $output = array(); $Nums = range(0,9); foreach ($Nums as $num) { $out[] = $num*=$num; } print_r($out); to get: Array ( [0] => 0 [1] => 1 [2] => 4 ...

How do I tell DOMDocument->load() what encoding I want it to use?

I search for and process XML files from elsewhere, and need to transform them with some XSLTs. No problem. Using PHP5 and the DOM library, everything's a snap. Worked fine, up till now. Today, funky characters were in the XML file -- "smart" quotes from Word, it looks like. Anyways, DOMDocument->load complained about them, saying that th...

refresh the div tag on click of the delete record

i'm using the prototype.js , PDO , PHP. i want to delete the records with refresh using ajax index.php <?php if(!isset($studentVoList)||count($studentVoList)==0){?> <tr><td colspan="3" align="center">No records found.</td></tr> <?php } else { foreach($studentVoList as $studentVo) { ?> <tr> <td align="center"><?php ech...

html to php change

if i change the extension of html file as .php means it will make any changes..? ...

Strict xml validation in php

I'm trying to fully validate an xml file which may be published by a user before it's fully published and live - it's basically somewhat like a sitemap.xml and it absolutely can't be published without being error-proof ( yes, I do have my own custom dtd for it as well ). I was also thinking of implementing a storage system so it would s...

Suppressing errors beyond setting ERROR_REPORTING ( display_errors perhaps? )

Let's say I'm basically inheriting a live site that has a lot of errors in production, I'm basically doing a recode of this entire site which might take a month or so. There are some cases in which this site was reliant upon external xml file feeds which are no longer there, but the code wasn't properly setup to supply a nice clean err...

Extracting link display text as well as href attribute with PHP 5

$oldSetting = libxml_use_internal_errors( true ); libxml_clear_errors(); I have seen many examples on the web on how to extract the URLs from HTML with PHP 5's DOM functions, but I need to get the link text as well as the link. If I use the code below to extract the link "http//X.com" from the "href" attribute in the anchor tag YYYYY, h...

If IE 6 , I want to produce warning and free download other browser icons

My web site want to be open IE7 and above .If IE 6 ,I want to produce warning and free download other browser icons .Is it possible? ...

PHP OOP lines usage explanation

What is the purpose of these lines: <?php $title=($cfg && is_object($cfg))?$cfg->getTitle():'Apptitle :: My First App'; ?> <?=Format::htmlchars($title)?> Can someone explain the usage here? I see the top line being used as first line in a php file, then the second line being used to populate the title. Why this implementation? Wh...

How to remove values from an array in PHP?

Is there a PHP function to remove certain array elements from an array? E.g., I have an array (A) with values and another array (B) from which a need to remove values. Want to remove the values in array A from array B? ...

php 5 $_SERVER['SERVER_ADDR'] with multiple IPs

I'm running an ubuntu jaunty server with 2 network interfaces configured: one public IP, one private. When I request the server IP I get the public IP. If I've got multiple interfaces is there a best practice for assuring I'm getting the public one (which is what I want)? <?php echo " <table>"; echo "<tr><td>" .$_SERVER['SERVER_ADDR']...

WYSIWYG HTML editor, but limit to certain tags by context

Hi all, I want to provide my users with the ability to edit blocks of content on the sites I've designed for them. Most blocks are contained in a <div>, and the users can have free choice of the HTML they use inside the block. However, there are some blocks which are contained in, for example, <ul> tags, and I want to limit the users ...

Why is $_POST empty in PHP5 under Apache?

In the file http://example.com/path/foo.php, I have the form (formatting deleted): <form action="/path/foo.php" method="post"> Email: <input type="text" name="email"> Password: <input type="password" name="password"> <input type="checkbox" name="remember" checked="checked"> Remember me <input type="submit" value="Log In"> </form> Some...

PHP __Constructor & __Destructor Questions...

I've been trying to learn the object oriented side of PHP, and was wondering: If I used a _constructor to open a connection to a database, used a function within that class (eg. insert), would the defined __destructor close the connection after the method "insert" is executed? class data(){ function __constructor { // connect to ...

How to verify a given string is a real URL, in PHP?

I need to find the best way (in terms of performance) to find if a given string is a URL. REGEXP won't help, as www.eeeeeeeeeeeeeee.bbbbbbbbbbbbbbbb.com is a valid url name but not in any network known to man. I am thinking using CURL and see if I get status 200 back or just file_get_contents and analyze the result. Is there a better way...

Simple PHP classes question.

So I have: class foo { public $variable_one; public $variable_two; function_A(){ // Do something $variable_one; $variable_two; // If I define variable_3 here! $variable_3 // Would I be able to access it in function_B? } function_B(){ // Do something $variable_4 = $variable_3 } } $myObj = ...