Discussion Locked

DOWNLOAD: 11 PHP functions for parsing and manipulating URLs and HTML

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

https://www.techrepublic.com.com/5138-10548-5655127.html

[b]The table in the download lists some of the more useful PHP functions parsing and manipulating functions, but what functions are missing?[/b]

[i]Thanks,
The Downloads Team[/i]

10 replies

by apotheon

. . . but you may be a dumb user. Check on whether Firefox is blocking the download popup when you try to download it.

by tony hopkinson

Turned out I'd set adblock to kill images from dw.com.com, which is of course where the Download button image comes from.
Silly Me.

by jaqui

Verbatim
tag, inside an
// opening paragraph (

) tag. Attributes for the table may be supplied
// as an array.

function start_table ($atts="")
{
$attlist = get_attlist($atts);
$output = <<

EOQ;
return $output;
}

// string end_table (void)

// This function returns a closing

tag, followed by a closing
// paragraph (

) tag. (Presumably closing the paragraph opened by
// start_table().)

function end_table ()
{
$output = <<

EOQ;
return $output;
}

// string table_cell ([string value [, array attributes]])

// This function returns an HTML table cell (

EOQ;
return $output;
}

// string table_row ([mixed ...])

// This function returns an HTML table row (

) tag, enclosing a variable
// number of table cell (

tag. All other
// arguments will be used as values for the cells of the row. If an
// argument begins with a

EOQ;
return $output;
}

?>

) tag. The first
// argument will be used as the value of the tag. Attributes for the
//
tag may be supplied as an array in the second argument.
// By default, the table cell will be aligned left horizontally,
// and to the top vertically.

function table_cell ($value="",$atts="")
{
$attlist = get_attlist($atts,array("align"=>"left","valign"=>"top"));

$output = <<$value

) tags. If any of the arguments to the function
// is an array, it will be used as attributes for the
tag, the argument is added to the row as is.
// Otherwise it is passed to the table_cell() function and the resulting
// string is added to the row.

function table_row ()
{
$attlist = "";
$cellstring = "";

$cells = func_get_args();
while (list(,$cell) = each($cells))
{
if (is_array($cell))
{
$attlist .= get_attlist($cell);
}
else
{
if (!eregi("
$cellstring

by jaqui

Verbatim
tag. The default font size is
// 2, and the default font typeface is sans-serif. Additional attributes
// for the tag may be supplied as an array in the third argument.

function font_tag($size="2",$face="sans-serif",$atts="")
{
$attlist = get_attlist($atts,array("size"=>$size,"face"=>$face));
$output = "";
return $output;
}

// string anchor_tag ([string href [, string text [, array attributes]]])

// This function returns an HTML anchor tag (). The first argument
// be the URL to which the tag points, and the second argument will
// be the text of the tag. Additional attributes may be supplied as
// an array in the third argument.

function anchor_tag($href="",$text="",$atts="")
{
$attlist = get_attlist($atts,array("href"=>$href));
$output = "$text";
return $output;
}

// string image_tag ([string src [,array attributes]])

// This function returns an HTML image tag (). The first argument
// gives theURL of the image to be displayed. Additional attributes
// may be supplied as an array in the third argument.

function image_tag($src="",$atts="")
{
$attlist = get_attlist($atts,array("src"=>$src));
$output = "";
return $output;
}

// string subtitle ([string text of subtitle])

// This function returns an HTML

tag. It is used for the titles
// of secondary areas within pages in our examples. The reason to
// display these via a function, rather than just literal

tags,
// is to enable you to change the format of these subtitles in one
// place, instead of in each script.

function subtitle($what="")
{
return "

$what

\n";
}

// string paragraph ([array attributes [, mixed ...]])

// This function will return a string inside HTML paragraph (

) tags.
// Attributes for the

tag may be supplied in the first argument.
// Any additional arguments will be included inside the opening and
// closing

tags, separated by newlines.

function paragraph ($atts="")
{
$output = " "")
{
$output .= " $attlist";
$i++;
}
$output .= ">\n";
$args = func_num_args();
while ($i < $args)
{
$x = func_get_arg($i);
$output .= $x."\n";
$i++;
}
$output .= "

\n";
return $output;
}

// string ul_list ([mixed values])

// This function returns an HTML unordered (bulleted) list (

    tags).
    // If the argument is an array, then each value from the array will be
    // included as a list item (

  • ) in the list. Otherwise, the
    // argument will simply be included inside the

      tags as is.

      function ul_list ($values="")
      {
      $output .= "

        \n";
        if (is_array($values))
        {
        while (list(,$value) = each($values))
        {
        $output .= "

      • $value\n";
        }
        }
        else
        {
        $output .= $values;
        }
        $output .= "

      \n";
      return $output;
      }

      ?>

by jaqui

Verbatim
tag. If the first argument
// is empty, the value of the global Apache variable SCRIPT_NAME
// is used for the 'action' attribute of the tag.

function end_form ()
{
$output = <<
EOQ;
return $output;
}

// string text_field ([string name [, string value [, int size [, int maximum length]]]])

// This function returns an HTML text input field. The default size
// of the field is 10. A value and maximum data length for the field
// may be supplied.

function text_field ($name="", $value="", $size=10, $maxlen="")
{
$maxatt = empty($maxlen) ? "" : "maxlength=\"$maxlen\"";
$output = <<
EOQ;
return $output;
}

// string textarea_field([string name [, string value [, int cols [, int rows [, string wrap mode]]]]])

// This function returns an HTML textarea field. The default size is
// 50 columns and 10 rows, and the default wrap mode is 'soft', which means
// no hard newline characters will be inserted after line breaks in what
// the user types into the field. The alternative wrap mode is 'hard',
// which means that hard newlines will be inserted.

function textarea_field ($name="", $value="", $cols=50, $rows=10, $wrap="soft")
{
$output = <<$value
EOQ;
return $output;
}

// string password_field ([string name [, string value [, int size [, int maximum length]]]])

// This function returns an HTML password field. This is like a text field,
// but the value of the field is obscured (only stars or bullets are visible
// for each character). The default size of the field is 10. A starting
// value and maximum data length may be supplied.

function password_field ($name="", $value="", $size=10, $maxlen="")
{
$output = <<
EOQ;
return $output;
}

// string hidden_field ([string name [, string value]])

// This function returns an HTML hidden field. A value may be supplied.

function hidden_field ($name="", $value="")
{
$output = <<
EOQ;
return $output;
}

// string file_field ([string name])

// This function returns an HTML file field. These are used to specify
// files on the user's local hard drive, typically for uploading as
// part of the form. (See http://www.zend.com/manual/features.file-upload.php
// for more information about this subject.)

function file_field ($name="")
{
$output = <<
EOQ;
return $output;
}

// string submit_field ([string name [, string value]])

// This function returns an HTML submit field. The value of the field
// will be the string displayed by the button displayed by the user's
// browser. The default value is "Submit".

function submit_field ($name="", $value="")
{
if (empty($value)) { $value = "Submit"; }

$output = <<
EOQ;
return $output;
}

// string image_field ([string name [, string src [, string value]]])

// This function returns an HTML image field. An image field works
// likes a submit field, except that the image specified by the URL
// given in the second argument is displayed instead of a button.

function image_field ($name="", $src="", $value="")
{
if (empty($value)) { $value = $name; }

$output = <<
EOQ;
return $output;
}

// string reset_field ([string name [, string value]])

// This function returns an HTML reset field. A reset field returns
// the current form to its original state.

function reset_field ($name="reset", $value="Reset")
{
$output = <<
EOQ;
return $output;
}

// string checkbox_field ([string name [, string value [, string label [, string match]]]])

// This function returns an HTML checkbox field. The optional third argument
// will be included immediately after the checkbox field, and the pair
// is included inside a HTML tag - meaning that they will be
// displayed together on the same line. If the value of the
// second or third argument matches that of the fourth argument,
// the checkbox will be 'checked' (i.e., flipped on).

function checkbox_field ($name="", $value="", $label="", $match="")
{
$checked = ($value == $match || $label == $match) ? "checked" : "";
$output = << $label
EOQ;
return $output;
}

// string radio_field ([string name [, string value [, string label [, string match]]]])

// This function returns an HTML radio button field. The optional third
// argument will be included immediately after the radio button, and the pair
// is included inside a HTML tag - meaning that they will be
// displayed together on the same line. If the value of the
// second or third argument matches that of the fourth argument,
// the radio button will be 'checked' (i.e., flipped on).

function radio_field ($name="", $value="", $label="", $match="")
{
$checked = ($value == $match || $label == $match) ? "checked" : "";
$output = << $label
EOQ;
return $output;
}

// string select_field ([string name [, array items [, string default value]]])

// This function returns an HTML select field (a popup field).
// If the optional second argument is an array, each key in the array
// will be set to the value of an option of the select field, and
// the corresponding value from the array will be the displayed string
// for that option. If the key or the value from the array matches
// the optional third argument, that option will be designated as the default
// value of the select field.

function select_field ($name="", $array="", $value="")
{
$output = <<
EOQ;
if (is_array($array))
{
while (list($avalue,$alabel) = each($array))
{
$selected = ($avalue == $value || $alabel == $value) ?
"selected" : ""
;
$output .= <<$alabel
EOQ;
}
}
$output .= <<
EOQ;
return $output;
}

// string db_select_field ([string name [, string table name [, string value field [, string label field [, string sort field [, string match text [, string where clause]]]]]]])

// This function returns an HTML select field (popup field), based
// on the values in the MySQL database table specified by the second argument,
// as returned by the db_values_array() function (defined in
// /book/functions/db.php).

function db_select_field ($name="", $table="", $value_field=""
, $label_field="", $sort_field="", $match="", $where=""
)
{
$values = db_values_array($table, $value_field, $label_field
, $sort_field, $where
);
$output = select_field($name, $values, $match);
return $output;
}

// string db_radio_field (string name, string table name, string value field, string label field, string sort field, [string match text], [string where clause])

// This function returns a list of HTML radio button fields, separated
// by a non-breaking space HTML entity ( ) and a newline, based
// on the values in the MySQL database table named by the second
// argument, as returned by the db_values_array() function (defined in
// /book/functions/db.php).

function db_radio_field ($name="", $table="", $value_field=""
, $label_field="", $sort_field="", $match="", $where=""
)
{
$values = db_values_array($table, $value_field, $label_field
, $sort_field, $where
);

$output = "";
while (list($value, $label) = each($values))
{
$output .= radio_field($name, $value, $label, $match)
." \n"
;
}
return $output;
}

?>

by Mark W. Kaelin

Thanks for posting the PHP functions - a very nice enchancement to the download.

The emoticons stem from particular character sequences that you can see when you hover over them.

The can be prevented by wrapping code in [pre]pre Code Here /pre[/pre] indicators (put brackets [ ] around them).

A link describing all of those "features" should probably be on this page somewhere ]:)

https://www.techrepublic.com.com/5100-22_11-5272932.html

by apotheon

Of course, the problem with [pre]pre tags[/pre] is that they don't wrap properly or play nicely as inline text (at least, they don't if the pre tags with brackets here map directly to HTML pre tags with < and >).

by jaqui

the functions actually came from the php&mysql book I bought to learn php years ago.

usefull functions for any php site to have available.
and, since from manual cdrom, well documented in purpose. which helps people to use appropriately.

as Oz pointed out to me,
for posting code the Verbatim tag is usefull, as it kills all tr formatting.
leaving just the text as entered.
no making smileys out of the : ) combinations.

by apotheon

We all have our dumb days, I suppose. I've had a few myself. It's a good thing this dumb moment of yours didn't cause a top-100 website to crash.

This discussion is closed to new replies.