php

PHP PREG Question

As hard as I try, PREG and I don't get along, so, I am hoping one of you PHP gurus can help out .. I have some HTML source code coming in to a PHP script, and I need specific items stripped out/removed from the source code. First, if this comes in as part of HTML (could be multiple instances): <SPAN class=placeholder title="" jQuery12...

Custom rendering of Zend_Navigation

I am using a navigation XML file in conjunction with my Zend Framework MVC app. A top level menu is rendered at the top of my layout. The code to produce it looks like this: $this->navigation()->menu()->renderMenu(null,array('maxDepth' => 0)); This will automatically render an unordered list of links that I have styled into my top...

get atom feed and display in html (google-api)

Hello, Can someone help me out on this. I have a problem with the return results from an google-api call I want to echo them back as html, but firefox keeps displaying a feed page. In IE, I get an error saying that an xml document can only contain one toplevel element wich must be the atom "feed" element, so I don't get that. What ca...

Google-like search functions

I asked this question about a year ago on another site but never got the answers I was looking for. And I've been wondering about it ever since. I'd like to impliment some search functions similar to Google's (inurl:foo, site:bar.com) So if you entered a normal query, with none of these functions included, it would search one column. ...

How to improve my Algorithm to find the Hot-Topics like twitter does.

I have created a cron job for my website which runs every 2hours and it counts the words in the feeds, and then displays the 10 highest count words as the hot topics. Some thing what twitter does on there homepage, to show the most popular topics that are being discussed. What my cron job does right now is it counts the words except ...

Dynamic Titles question

How would I make it possible to have dynamic(i think thats the word) titles with this setup? For example when I'm viewing a profile I want it to say Viewing profile of USERNAME' inside <title>. How could I make this possible without putting the html top on each indivudual page? Thanks a lot. and please dont start talking about mvc's, i...

How to use HTTP cache headers with PHP

Hello! I have a PHP 5.1.0 website (actually it's 5.2.9 but it must also run on 5.1.0+). Pages are generated dynamically but many of them are mostly static. By static I mean the content don't change but the "template" around the content can change over time. I know they are several cache systems and PHP frameworks already out there, bu...

MySQL > JSON, Causing errors with URL's

I have this code converting a mysql query to json: $sth = mysql_query('SELECT * FROM `staff` ORDER BY `id` DESC LIMIT 20') or die(mysql_error()); $rows = array(); while($r = mysql_fetch_array($sth)) { $rows[] = $r; } print json_encode($rows); Works great, but i have in my database, a url field, here is a sample json row: {"0":"4"...

PHP OOP dilemma: how to keep a database connection 'within' a class object?

And here i am again! ;) Im developing (well, im still in planning phase) a web-app where i would give to other developer the possibility to write theyr own plugins/modules (in the way of CMS does, drupal, joomla, etc). My problem is that i have to force the developers to use the methods i wrote for interact with databases, for many rea...

json_encode is returning null?

For some reason the item "description" returns null with the following code: <?php include('db.php'); $result = mysql_query('SELECT * FROM `staff` ORDER BY `id` DESC LIMIT 2') or die(mysql_error()); $rows = array(); while($row = mysql_fetch_assoc($result)){ $rows[] = $row; } echo json_encode($rows); ?> Here is the schema for my ...

Getting the first character of a string with $str[0]

I want to get the first letter of a string and I've noticed that $str[0] works great. I am just not sure whether this is 'good practice', as that notation is generally used with arrays. This feature doesn't seem to be very well documented so I'm turning to you guys to tell me if it's all right in all respects to use this notation? Or ...

Best Practise of Making notifications for logged in user

Hi. I am making a web-site , which is a social network. There is need of making overall notification block/bar on the website. User should be notified when a) there is new message b) there is new friend request c) there is new photo rating .... As application (php/mysql) should be made with future calculation of minimum 100-1500 us...

[PHP]: Logic with date differences

Hi, I'm seeking an elegant solution to change the format of time based on the length of time between now, and a ISO formated date in a DB. I'd like the output to look something like this //less than an hour 'X minutes have gone by' //less than 24 hours 'X hours have gone by' //greater than 24 hours ISO date Here is what I have so fa...

Using jQuery, what's the best way to set up a polling system?

During a document.ready, I call the "load_result" function outlined below: function load_result() { $.getJSON( "http://www.mywebsite.com/loadresult.php", function(data) { if( data == undefined ) { null_count++; return; } console.log( data ); insert_result( data ); ...

How can I build my own version of facebook FQL?

On facebook many of you probably know of there API which uses there own FQL (facebook version of a mysql query) I am curious, how could I support my own user submitted queries in the same manner on my site? Do you basicly pass in the custom query into a function, in the function you just use regex to match SELECT from ect? Hope m...

MySQL vs MySQLi in PHP

What are the differences/advantages of each? Disadvantages? I'm not looking for coding preferences or subjective answers. What are practical diferences? (Storage, implementation, how the code looks, environment requirements...) ...

Best way to know when users register duplicated links (MYSQL + PHP)

so i have a page where a user can submit his own links i dont want to make a script that do everything automatic, i just want to make a page where, when the .php find a possible duplicated link, i get a warning like "ID 22 could possible have the same link as ID 738" i only need like the query to do that...if its possible with that..i ...

Convert CURL to fosckopen in PHP

I am working on setting up credit card processing for a site that is live. PHP wasn't compiled with CURL support and I don't want to take the site down to recompile PHP with that, so I am trying to use a different method than the example code provided. Example CURL code: function send($packet, $url) { $header = array("MIME-Version...

put <em> and </em> in the beginning and end of each found keywords

im new to preg and wants to find some strings i got in an array and emphasize each one. eg. array[0] = "windows"; array[0] = "windows xp"; text will be: <em>windows</em> is bla bla...<em>windows xp</em> is bla bla how could i do that? ...

When strip_tags() Burns a Haystack

I've got a list of websites for each US Congress member that I'm programmatically crawling to scrape addresses. Many of the sites vary in their underlying markup, but this wasn't initially a problem until I started seeing that hundreds of sites were not giving the expected results for the script I had written. After taking some more tim...