Remplazar palabras mysql
16 de Enero de 2011Para poder remplazar de manera automática palabras en una base de datos mysql
UPDATE tabla SET campo = replace( campo, ‘original’, ‘remplazar’ ) ;
Para poder remplazar de manera automática palabras en una base de datos mysql
UPDATE tabla SET campo = replace( campo, ‘original’, ‘remplazar’ ) ;
Para mostrar resultados aleatorios desde una base de datos mysql esta es la query:
$query=”SELECT * FROM $table $conditions ORDER BY RAND() LIMIT $limit”;
Limit: solo podrá contener un número que será la cantidad de resultados obtenidos
Para remplazar palabras en una base de datos mysql
update table set field = replace(field, 'original', 'remplace');
Para solucionar el problema de los acentos en ajax al retornar resultados con acentos y otros caracteres especiales:
header(’Content-Type: text/html; charset=ISO-8859-1′);
setlocale(LC_CTYPE,”es_ES”);
Para alinear los textos en los checkbox hay que hacer una etiqueta que englobe al texto y al input.
#container label.check * {
vertical-align: middle;
}
Solo hay que poner la función myLytebox.updateLyteboxItems(); después del responseText
if ( xmlhttp.readyState == 4 && xmlhttp.status == 200 ) {
obj.innerHTML = xmlhttp.responseText;
myLytebox.updateLyteboxItems();
}
function get_doctype($file){
$h1tags = preg_match(‘/<!DOCTYPE (\w.*)dtd”>/is’,$file,$patterns);
$res = array();
array_push($res,$patterns[0]);
array_push($res,count($patterns[0]));
return $res;
}
// retrieve page title
function get_doc_title($file){
$h1tags = preg_match(‘/<title> ?.* <\/title>/isx’,$file,$patterns);
$res = array();
array_push($res,$patterns[0]);
array_push($res,count($patterns[0]));
return $res;
}
// retrieve keywords
function get_keywords($file){
$h1tags = preg_match(‘/(<meta name=”keywords” content=”(.*)” \/>)/i’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// get rel links in header of the site
function get_link_rel($file){
$h1tags = preg_match_all(‘/(rel=)(”.*”) href=(”.*”)/im’,$file,$patterns);
$res = array();
array_push($res,$patterns);
array_push($res,count($patterns[2]));
return $res;
}
function get_external_css($file){
$h1tags = preg_match_all(‘/(href=”)(\w.*\.css)”/i’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve all h1 tags
function get_h1($file){
$h1tags = preg_match_all(“/(<h1.*>)(\w.*)(<\/h1>)/isxmU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve all h2 tags
function get_h2($file){
$h1tags = preg_match_all(“/(<h2.*>)(\w.*)(<\/h2>)/isxmU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve all h3 tags
function get_h3($file){
$h1tags = preg_match_all(“/(<h3.*>)(\w.*)(<\/h3>)/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve all h4 tags
function get_h4($file){
$h1tags = preg_match_all(“/(<h4.*>)(\w.*)(<\/h4>)/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve all h5 tags
function get_h5($file){
$h1tags = preg_match_all(“/(<h5.*>)(\w.*)(<\/h5>)/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve all h5 tags
function get_h6($file){
$h1tags = preg_match_all(“/(<h6.*>)(\w.*)(<\/h6>)/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve p tag contents
function get_p($file){
$h1tags = preg_match_all(“/(<p.*>)(\w.*)(<\/p>)/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve names of links
function get_a_content($file){
$h1count = preg_match_all(“/(<a.*>)(\w.*)(<.*>)/ismU”,$file,$patterns);
return $patterns[2];
}
// retrieve link destinations
function get_a_href($file){
$h1count = preg_match_all(‘/(href=”)(.*?)(”)/i’,$file,$patterns);
return $patterns[2];
}
// get count of href’s
function get_a_href_count($file){
$h1count = preg_match_all(‘/<(a.*) href=\”(.*?)\”(.*)<\/a>/’,$file,$patterns);
return count($patterns[0]);
}
//get all additional tags inside a link tag
function get_a_additionaltags($file){
$h1count = preg_match_all(‘/<(a.*) href=”(.*?)”(.*)>(.*)(<\/a>)/’,$file,$patterns);
return $patterns[3];
}
// retrieve span’s
function get_span($file){
$h1count = preg_match_all(‘/(<span .*>)(.*)(<\/span>)/’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve spans on the site
function get_script($file){
$h1count = preg_match_all(‘/(<script.*>)(.*)(<\/script>)/imxsU’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve content of ul’s
function get_ul($file){
$h1count = preg_match_all(‘/(<ul \w*>)(.*)(<\/ul>)/ismxU’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
//retrieve li contents
function get_li($file){
$h1count = preg_match_all(‘/(<li \w*>)(.*)(<\/li>)/ismxU’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve page comments
function get_comments($file){
$h1count = preg_match_all(‘/(<!–).(.*)(–>)/isU’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve all used id’s on the page
function get_ids($file){
$h1count = preg_match_all(‘/(id=”(\w*)”)/is’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve all used classes ( inline ) of the document
function get_classes($file){
$h1count = preg_match_all(‘/(class=”(\w*)”)/is’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// get the meta tag contents
function get_meta_content($file){
$h1count = preg_match_all(‘/(<meta)(.*=”(.*)”).\/>/ix’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// get inline styles
function get_styles($file){
$h1count = preg_match_all(‘/(style=”)(.*?)(”)/is’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// get titles of tags
function get_tag_titles($file){
$h1count = preg_match_all(‘/(title=)”(.*)”(.*)/’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// get image alt descriptions
function get_image_alt($file){
$h1count = preg_match_all(‘/(alt=.)([a-zA-Z0-9\s]{1,})/’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
// retrieve images on the site
function get_images($file){
$h1count = preg_match_all(‘/(<img)\s (src=”([a-zA-Z0-9\.;:\/\?&=_|\r|\n]{1,})”)/isxmU’,$file,$patterns);
$res = array();
array_push($res,$patterns[3]);
array_push($res,count($patterns[3]));
return $res;
}
// retrieve email address of the mailto tag if any
function get_mailto($file){
$h1count = preg_match_all(‘/(<a\shref=”)(mailto:)([a-zA-Z@0-9\.]{1,})”/ims’,$file,$patterns);
$res = array();
array_push($res,$patterns[3]);
array_push($res,count($patterns[3]));
return $res;
}
// retrieve any email
function get_emails($file){
$h1count = preg_match_all(‘/[a-zA-Z0-9_-]{1,}@[a-zA-Z0-9-_]{1,}\.[a-zA-Z]{1,4}/’,$file,$patterns);
$res = array();
array_push($res,$patterns[0]);
array_push($res,count($patterns[0]));
return $res;
}
// count used keywords
function countkeyword($word,$file){
$x = preg_match_all(“/(.*)($word)(.*)/”,$file,$patterns);
return count($patterns);
}
// retrieve internal site links
function get_internal_links($array){
$result = array();
$count = count($array);
for($i=0;$i<$count;$i++){
if(!empty($array[$i])){
if(strpos($array[$i],“www”,0) === false){
if(strpos($array[$i],“http”,0) === false){
array_push($result,$array[$i]);
}
}
}
}
return $result;
}
// retrieve external links
function get_external_links($array){
$result = array();
$count = count($array);
for($i=0;$i<$count;$i++){
if(!empty($array[$i])){
if(strpos($array[$i],“www”,0) !== false){
if(strpos($array[$i],“http”,0) !== false){
array_push($result,$array[$i]);
}
}
}
}
return $result;
}
// retrieve the main url of the site
function get_main_url($url){
$parts = parse_url($url);
$url = $parts["scheme"] .“://”.$parts["host"];
return $url;
}
// retrieve just the name without www and com/eu/de etc
function get_domain_name_only($url){
$match = preg_match(“/(.*:\/\/)\w{0,}(.*)\.(.*)/”,$url,$patterns);
$patterns[2] = str_replace(“.”,“”,$patterns[2]);
return $patterns[2];
}
?>
Usage Example
|
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <body><form action=”" method=”post” enctype=”application/x-www-form-urlencoded” name=”form1″> <?php if(isset($_POST['submit']) && $_POST['submit'] == “submit”){ if(strpos($url,“http”,0) === false){ echo “<img src=\”http://www.artviper.net/screenshots/screener.php?url=$url&h=180&w=240&sdx=1024&sdy=768\” alt=\”$url\” style=\”margin:20px\” />”; $file = file_get_contents($url); echo“<h1>Document properties</h1>”; // get doc title // get external references CSS files // get keywords echo“<h1>Content properties</h1>”; // get h3 tags echo “<h1>Link structure</h1>”; if(!empty($links[0])){ if(!empty($href_add[0])){ echo “<h1>Images</h1>”; if(!empty($images[0])){ echo “<h1>Styles, ID’s & Classes</h1>”; if(!empty($ids[0])){ if(!empty($classes[0])){ if(!empty($styles[0])){ |
// See related links for more status codes
// Use this header instruction to fix 404 headers
// produced by url rewriting…
header(’HTTP/1.1 200 OK’);
// Page was not found:
header(’HTTP/1.1 404 Not Found’);
// Access forbidden:
header(’HTTP/1.1 403 Forbidden’);
// The page moved permanently should be used for
// all redrictions, because search engines know
// what’s going on and can easily update their urls.
header(’HTTP/1.1 301 Moved Permanently’);
// Server error
header(’HTTP/1.1 500 Internal Server Error’);
// Redirect to a new location:
header(’Location: http://www.example.org/’);
// Redriect with a delay:
header(’Refresh: 10; url=http://www.example.org/’);
print ‘You will be redirected in 10 seconds’;
// you can also use the HTML syntax:
// <meta http-equiv=”refresh” content=”10;http://www.example.org/ />
// override X-Powered-By value
header(’X-Powered-By: PHP/4.4.0′);
header(’X-Powered-By: Brain/0.6b’);
// content language (en = English)
header(’Content-language: en’);
// last modified (good for caching)
$time = time() - 60; // or filemtime($fn), etc
header(’Last-Modified: ‘.gmdate(’D, d M Y H:i:s’, $time).’ GMT’);
// header for telling the browser that the content
// did not get changed
header(’HTTP/1.1 304 Not Modified’);
// set content length (good for caching):
header(’Content-Length: 1234′);
// Headers for an download:
header(’Content-Type: application/octet-stream’);
header(’Content-Disposition: attachment; filename=”example.zip”‘);
header(’Content-Transfer-Encoding: binary’);
// load the file to send:
readfile(’example.zip’);
// Disable caching of the current document:
header(’Cache-Control: no-cache, no-store, max-age=0, must-revalidate’);
header(’Expires: Mon, 26 Jul 1997 05:00:00 GMT’); // Date in the past
header(’Pragma: no-cache’);
// set content type:
header(’Content-Type: text/html; charset=iso-8859-1′);
header(’Content-Type: text/html; charset=utf-8′);
header(’Content-Type: text/plain’); // plain text file
header(’Content-Type: image/jpeg’); // JPG picture
header(’Content-Type: application/zip’); // ZIP file
header(’Content-Type: application/pdf’); // PDF file
header(’Content-Type: audio/mpeg’); // Audio MPEG (MP3,…) file
header(’Content-Type: application/x-shockwave-flash’); // Flash animation
// show sign in box
header(’HTTP/1.1 401 Unauthorized’);
header(’WWW-Authenticate: Basic realm=”Top Secret”‘);
print ‘Text that will be displayed if the user hits cancel or ‘;
print ‘enters wrong login data’;
function Capitalizar($nombre) {
// aca definimos un array de articulos (en minuscula)
// aunque lo puedes definir afuera y declararlo global aca
$articulos = array(
‘0′ => ‘a’,
‘1′ => ‘de’,
‘2′ => ‘del’,
‘3′ => ‘la’,
‘4′ => ‘los’,
‘5′ => ‘las’,
‘6′ => ‘y’,
‘7′ => ‘i’,
);
// explotamos el nombre
$palabras = explode(’ ‘, $nombre);
// creamos la variable que contendra el nombre
// formateado
$nuevoNombre = ”;
// parseamos cada palabra
foreach($palabras as $elemento)
{
// si la palabra es un articulo
if(in_array(trim(strtolower($elemento)), $articulos))
{
// concatenamos seguido de un espacio
$nuevoNombre .= strtolower($elemento).” “;
} else {
// sino, es un nombre propio, por lo tanto aplicamos
// las funciones y concatenamos seguido de un espacio
$nuevoNombre .= ucfirst(strtolower($elemento)).” “;
}
}
return trim($nuevoNombre);
}
function get_content($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
}
$palabras = get_content ($url”);