Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Oliver Haag www.ohcon.de

« Newer Snippets
Older Snippets »
Showing 21-30 of 30 total

check url with php

// description of your code here

function http_test_existance($url) {
 return (($fp = @fopen($url, 'r')) === false) ? false : @fclose($fp);
}

evaluate form fields with php

// contains all types of fields

// of special interest are selection boxes.
// They can return an array.
// Here is a quick evaluation with implode().

<!-- Formular auswerten (evaluate form)
     ********************************** -->

<?php
$hidden_value_1 = $_POST['hval1'];
$hidden_value_2 = $_POST['hval2'];

$short_text	= $_POST['stext'];
$password	= $_POST['pwd'];
$long_text	= $_POST['ltext'];

$selected_option = $_POST['optn'];
$radio_selection = $_POST['radsel'];

$check_selection = $_POST['checksel'];
$check_text = implode(', ',$check_selection);
?>



<html><body>
<h1>Kurze Anzeige (show values)</h1>
Versteckte Werte: <?=$hidden_value_1?>, <?=$hidden_value_2?><br>
Kurzer Text und Passwort: <?=$short_text?>, <span style="color: gray;"><?=$password?></span><br>
Langer Text:  <?=$long_text?><br>
Option: <?=$selected_option?><br>
Radio-Auswahl: <?=$radio_selection?><br>
CheckBox-Auswahl: <?=$check_text?>

<h1>Ein Formular (form)</h1>

<!-- Das Beispielformular (form example)
     ********************************** -->
<form action="form.php" method="post">

<!-- versteckte Elemente (hidden elements) -->
<input type="hidden" name="hval1" value="Der erste versteckte Wert">
<input type="hidden" name="hval2" value="Der zweite versteckte Wert">
<p>

<!-- einzeiliges Eingabefeld und Passwortfeld (text fields) -->
Kurzer Text und Passwort <br>
<input type="text" size="32" maxlength="64" name="stext" value="Kurze Textvorbelegung">
<input type="password" size="16" maxlength="16" name="pwd" value="geheim">
</p><p>

<!-- mehrzeiliges Eingabefeld (text area) -->
Langer Text <br>
<textarea cols="128" rows="4" name="ltext">
Optionale Textvorbelegung (optional text presetting): kann bei
mehrzeiligen Textfeldern lang sein,da genügend Platz vorhanden ist.
</textarea>
</p><p>

<!-- Auswahlliste mit Vorauswahl (selection list) -->
Option <br> <select name="optn">
<option selected>Die Erste Option</option>
<option>Die zweite Option</option>
<option>Die dritte Option</option>
</select>
</p><p>

<!-- Radio-Buttons mit Vorauswahl (radio buttons) -->
Radio-Auswahl <br>
<input type="radio" name="radsel" value="first">Die erste Radiowahl<br>
<input type="radio" name="radsel" value="seccond">Die zweite Radiowahl<br>
<input type="radio" name="radsel" value="third" checked> Die dritte Radiowahl
</p><p>

CheckBox-Auswahl <br>
<input type="checkbox" name="checksel[]" value="chk1" checked>Die erste Checkwahl<br>
<input type="checkbox" name="checksel[]" value="chk2" checked>Die zweite Checkwahl<br>
<input type="checkbox" name="checksel[]" value="chk3">Die dritte Checkwahl
</p><p>

<!-- Buttons zum Absenden/ Abbrechen (buttons to submit/reset) -->
<input type="submit" value="auswerten">
<input type="reset" value="zurücksetzen">

</form>
</body></html>

Confirm Delete with javascript

// confirm() returns true or false
// submit() is only called on true and submits the form

<h1>Howto Confirm Delete</h1>
<form action="delete.html" method="post">
<input type="button" onclick="if (confirm('sure?')) submit();" value="delete">
</form>

change text

// javascript to change text

<script type="text/javascript">
function changeText(txt){
	document.getElementById('the_text').innerHTML = txt;
}
</script>
<p>Hello <b id='name'>World</b>. </p>
<input type='button' onclick='changeText("Oliver")' value='Change Text'/>

geourl

// add website to geourl
// long desciption on http://geourl.org/add.html


#1 get coordinates

#2 add meta tags to head
<meta name="ICBM" content="XXX.XXXXX, YYY.YYYYY">
<meta name="DC.title" content="THE NAME OF YOUR SITE">

#3 ping http://geourl.org/ping/


// lots of backlinks
// but no change in pagerank (in 3 month)

replace file extension with apache rewrite

// in this example *.html is replaced by *.php
// its a redirect [R] and it is is permanent (code is 301)

RewriteEngine On
RewriteBase   /the_directory

RewriteRule  ^(.*).html$ $1.php [R=301]

rewrite rules

// if cms has cryptic urls
// in apache url-rewriting with .htaccess can help

RewriteRule cms/fest$ cms/index.php?option=content&task=view&id=176&Itemid=202 [NC]


// [NC] = not case-sensitive

center text

// center horizontally
// text-align:center for internet explorer, margin:auto for firefox

<div style="text-align:center">
<div style="margin:auto">the text</div>
</div>


// center vertically with table
<table><tr><td valign="middle">the text</td></tr></table>


// or without table (only firefox, .. / not in internet explorer <=6!)
<div style="display:table-cell;	vertical-align: middle">the text</div>

use google to search / find code snippet

// with google site search you can check for code snippets here

# google.com
search_term site:http://snippets.dzone.com

test if sites are online

// test if sites are online by title validation
// if the title can change, test can validate occurance of a phrase instead

require 'rwebunit'  # ruby web test based on watir (uses ie=internet-explorer-object)

# test if sites are online by title validation
# usage: to run this test without visible ie use the -b option
# C:\ruby\workspace\ruject1>ruby rwu_site_checker.rb -b

class RwuSiteChecker < RWebUnit::WebTestCase

  # hash with url and title
  @@sites = {
    "http://www.domain_number_one.de" => "title number one",
    "http://www.seccond_domain.org" => "seccond title",
    "http://www.yet_another_domain.com" => "yet another title"
  }
  
  # test for titles
  def test_titles()
    log = "testing title \n"
    @@sites.each { |url, title|
      getTestContext().base_url=url
      beginAt("/")
      assertTitleEquals(title)
      # to check for phrase: assertTextPresent(phrase) 
   
      log += url + " ok \n"
    }
    puts log
  end
  
end

« Newer Snippets
Older Snippets »
Showing 21-30 of 30 total