digital-ether 399 Nearly a Posting Virtuoso Team Colleague

In your code, try dumping the cotents of the array before you use array_filter().
EG:

var_dump($fee2_code);
$fee2_code = array_filter($fee2_code); //line 155

The error is because it isn't an array. Even though your HTML looks ok and it seem it should be an array.


It is difficult to understand what the callback is can you explain better than the PHP manual?

Note: I was looking at Example 2. array_filter() without callback.

The callback is a function that you define, that will be executed in another function.

If you were to implement callback functions in your own code, it could look something like:

/**
* Example of function using a callback. (same as array_filter except it will filter out empty strings also)
* @param array The array to filter
* @param function The callback function
*/
function my_array_filter($array, $callback = false) {

	if (!$callback) {
		$callback = 'trim'; // default callback function: trim()
	}

	$new_array = array(); // filtered array
	foreach($array as $index=>$value) {
		// execute the callback function passing it the argument: $value
		if (call_user_func($callback, $value)) {
			$new_array[$index] = $value;
		}
	}
	return $new_array;
}

/**
* Example of my_array_filter()
*/

$arr = array('hey', false, true, '0', ' ', '');

var_dump(my_array_filter($arr));
echo '<br />';
var_dump(array_filter($arr));

If you look at the function, my_array_filter, there is a line:

call_user_func($callback, $value)

call_user_function will execute a user defined function. Since this function name is passed as an argument in to a function, then it is called a callback.
It …

stymiee commented: excellent post - stymiee +2
digital-ether 399 Nearly a Posting Virtuoso Team Colleague


any better solutions..? o_O

EDIT: bah... that doesn't work though! who decided you can't have hyperlinked anchors in buttons? :| as i'm overriding the button graphical style anyway, i guess i can just emulate it with a div... i have to use JS to toggle the edges and padding to give a "clicked" appearance... but at least i don't have JS depandant functionality...

another solution.. is to absolutely place another form and button next to the submit button and use the form action... methinks that's messier.

Not really sure what you want...
But wouldn't

<a href="#" target="_blank"><input type="button" /></a>

work for you?
(You may have to define height and width for IE though).

If you're going to emula

te buttons with DIVs you'll definately have to do it will all buttons as you don't know what a button looks like on differnet platforms and browsers. But then you'll have to rely on JS to submit the form, and you dont what that.

You could probably just do something like:

<form name="real_form" ...>

<form target="blank" action="page_you_wanna_open.html">
<input type="submit" ... />
</form>

...

<input type="submit" name="real_submit" ... />

</form>

I don't think theres anything wrong with nesting forms?


Edit:

Or (but kinda ugly):

<form name="real_form" ...>

...

<input type="submit" name="real_submit" ... />

</form>

<form target="blank" action="page_you_wanna_open.html">
<input class="link_button" type="submit" ... />
</form>
<style>

input.link_button {
margin-top: = -[height of SUBMIT BUTTON]px;
margin-left: = [width of SUBMIT BUTTON …
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Btw: adding a href attribute to a div will make it invalid xHTML1.0. So even if you found a way to do it with CSS, you'd run into that problem. The solution would be to create a custom DTD for your document.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Is it possible to make an entire <div> into a hyperlink using CSS only, as can be easily accomplished with mouse events in JavaScript? I'm assuming it's too good to be true since CSS isn't interactive? Nevermind ... I guess I just answered my own question :(

Nope, unfortunately you're right. You can't emulate links on any other HTML element with CSS. You'll have to use JS for that.
If its an issue of support for javascript than I don't think there's any way around it, but if its just code choice then you could just attach say a class to the div element and have JS run through and give it link properties.

eg:

<div class="dlink" href="page.html">click me</div>
<script>
// assuming you can select elements by class
document.prototype.getElmentsByClass = function(className) { ... };

var dlinks = document.getElmentsByClass('dlink');
for(var x in dlinks) {
   var dlink = dlinks[x]; // closure (ie: dlink will be available in closure scope for onlick function when it is triggered in the window scope later on)
   dlink.onclick = function() { document.location.href = dlink.href; };
}
</script>

Even though its using JS, it emulates what you would normally do with CSS. However if you're working in an environment with only CSS on the client, then I don't believe it can be done.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi tefflox,

I found a few errors:

1) The array $ar has value a, b, c, etc which are undefined. What you actually want is strings:

$ar = array( 0 => 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f');

2) The style attribute fails because you have an extra slash in there. It should be:

$output .= "<span style=\"color:#";
        $output .= $col;
        $output .= "\">&mdash;&mdash;</span>";

3) In if(count >= 50) , count is undefined. It should be $count.

4) Most important, to concat strings in PHP use .= instead of += as + is the addition operator. Some languages use + to concat strings but php will first cast the integer type to the string before using the + operator. Strings with chars will evaluate to 0.

The logic is all ok except for using the for loop:

for($int = 0; $int < 50, $count < 50; $int++) {

This should really be a while loop since its more logical:

while( $count < 50 ) {

and will be simpler.

The rest of the logic is right on.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Headers already sent refers to HTTP Headers.
The server cannot send any more http headers if the HTTP Content has started sending.
In PHP code, this means you have ouput something to the page with echo or print etc.

PHP will not output any whitespace in between php tags, However, for anything outside php tags, (eg: html) whitespaces, linebreaks are sent as HTTP Content.
Sometimes this your editor may add whitespace also.

To prevent whitespace from being sent before you send all your headers, make sure the <?php is right at the top of the php script, and there are no lines or white space in between.

You can also use output buffering, ob_start() to buffer your PHP output before sending it to HTTP. Then use ob_flush() to send http output when you need.
see: http://www.php.net/manual/en/function.ob-start.php

I noticed you have //header("Location:admin_page.php"); in your page. You can use the output buffering to allow you to send this header even after you have echo and html output in your php.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

This assumes the sentence ends with a period. I can't remember if this function will take an array of delimiters or not.

$strings = split(".",$summary);
echo $strings[0];

Don't think it will take an array of delimiters. But you could use:

$strings = preg_split("/.|;|:/",$summary); // delimiters . ; : 
echo $strings[0];

which will achieve the same as taking an array of delimiters. Will bbe slower though.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Here's the link to ka-maps which is a javascript based map interface API.
http://ka-map.maptools.org

Theres also a list of other map resources and tools there at http://www.maptools.org/

As for adding custom head tags to mambo/joomla use:

mosMainFrame::addCustomHeadTag($string);

$string should contain your <script> reference.

Didn't get into ka-maps, seemed a bit harder than using google maps... lol.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Id go with google maps. I looked at msn's map API and even though they say its been in development longer than google maps, it seems to be a copy, as far as the API goes and just doenst match up. (maybe thats the best way to lay out the API? maybe everyone is used to Google Maps API, still its a coincidence).

For mambo, the only problem I can see is that you will have to add javascript to the head section of the html document. This can be done with mambo since mambo uses output buffering.
If you search the mambo API docs you will find the function for adding html/js to the head section, but this is only for later versions of mambo.
It also doesnt work in the admin panel, and with no_html enabled or on index2.php which loads only the mainbody.

If you add your js to the body of the html, it will most likely fail in ie, unless your doctype declaration validates successfully and is the doctype specified in the google maps API (cant remember which).
This is hard to do with mambo however, since validating the doctype depends on your template, components, modules, and usually will not even validate as xHTML 1.0 transitional.
(Joomla is better at this though :) )

There is an interactive map api offered open source, I believe you can find it at sourceforge.net. I can't remember where I saw it.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi J_

fopen allows you to append contnet to the beginning of the file by supplying 'r+' as the second param.

Something like:

$logfile= 'log.txt';
$IP = $_SERVER['REMOTE_ADDR'];
$logdetails=  date("F j, Y, g:i a") . ': ' . '<a href=http://dnsstuff.com/tools/city.ch?ip='.$_SERVER['REMOTE_ADDR'].' target=_blank>'.$_SERVER['REMOTE_ADDR'].'</a>';

// open the file for reading and writing
$fp = fopen($logfile, "r+");
// write out new log entry to the beginning of the file
fwrite($fp, $logdetails, strlen($logdetails));
fclose($fp);

A few suggestions:

Usually you would not want to add formatting (html or any other) into a log file, or file of the sort.

ie:

$logdetails=  date("F j, Y, g:i a") . ': ' . '<a href=http://dnsstuff.com/tools/city.ch?ip='.$_SERVER['REMOTE_ADDR'].' target=_blank>'.$_SERVER['REMOTE_ADDR'].'</a>';

What you would wnat to do is add just the data, and seperate each new entry either with a new line, or some other delimiter.
This way, you actually avoid having to write your content in any order.
You can format and sort the content in any way you want when you read your logs with php.
It also ensures that the data will be small and access to the file will be faster.

A simple example:

$logfile= 'log.txt';
/*
Your log could have a format like:
date : IP \n
date : IP \n
*/

// get log contents, trim starting, ending \n
$contents = trim(file_get_contents('log.txt'));

// create an array with each log entry using \n as seperator
$contents_arr = explode("\n", trim($contents));

// you can now apply any sorting you …
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Thanks for the info, i was wondering how i would be able to go about creating the admin side of the system, how would the administrators be able to create new polls for the system. Thanks

Its easy to just be concerned about the database first, as this will store the polls.
First create the structure for your database. If you look at existing poll scripts, you can view the database structure using phpmyadmin.

The idea would be to save the info needed for each individual poll, and all the form fields on the poll.

You could store each poll in a table called 'polls' with the columns, id, title, description, creator, date, published etc etc.
This singles out each poll and also allows you to keep track of who created it and when (creator, date) and if its published or not and other optional features.

You can then create a table for all the poll's form fields called poll_fields.
First you will need to make sure the poll fields are linked to an existing poll, so you give it a table column called poll_id. This will have the value of one of the id's of the rows in the 'polls' table.
Its also good to have an index for your poll_fields table, so you can give it an id column also. (so you can identify each row on its own)

Then you can add another table column called form_field, this will …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi, i am a computer science final year student, i was thinking of creating an online voting/polling system,the system could include surveys as well. I really need some ideas in designing the system and any idea you send to me will be highly appreciated.

The best way to tackle this I believe is to download an open source voting/polling script, and take a look at how it functions. (search sourceforge.net, hostscripts.com, google)
Most the polling scripts will come with a administration panel (the good ones at least), I dont believe its complete withought it, so you'll have to also look at developing both the polling frontend, and an admin area to manage, create the polls.
Theres a lot of ways to actually go about doing the project, but if I were to do it, I'd first create a simple templating system (having your php logic seperated from your design makes it much less confusing), then develop the admin panel first (think of how the database will store all the results, and how the admin will create the forms), then go on to the actual forms that will be the frontend.

Though it sounds simple, a polling system can be a lot of work.
If you want to really go overboard, try searching the web for AJAX, and use it to validate, populate, submit forms on the poll frontend.
There arent many ajax based polling systems out there open source, (i checked) …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I dont know why you would want to wrap str_replace with a class and function.
Its works ok by itself... ;)