<table>
<tr>
<td onclick="Copiar(this)">Hola soy un texto que se copia al darle clic</td>
<td onclick="Copiar(this)">Hola yo soy otro texto que se copia al darle clic</td>
</tr>
</table>
function Copiar(element) {
//creamos un input que nos ayudara a guardar el texto temporalmente
var $temp = $("<input>");
//lo agregamos a nuestro body
$("body").append($temp);
//agregamos en el atributo value del input el contenido html encontrado
//en el td que se dio click
//y seleccionamos el input temporal
$temp.val($(element).html()).select();
//ejecutamos la funcion de copiado
document.execCommand("copy");
//eliminamos el input temporal
$temp.remove();
}
Recargar shadowbox
este codigo recarga la pagina al cerrar el ligbox, colocar en la pagina padre.
<!--Aqui inicia el lightbox-->
<link rel="stylesheet" type="text/css" href="shadowbox.css">
<script type="text/javascript" src="shadowbox.js"></script>
<script type="text/javascript">
Shadowbox.init({
onClose:function(){window.location.reload(true); }
});
</script>
Pasar a Mayusculas
<script>
function mayus(e) {
e.value = e.value.toUpperCase();
}
</script>
onkeyup="mayus(this);"
<input type="text" onkeyup="mayus(this);">
<input type="text" onkeyup="mayus(this);">
----------------------------------------------------
metodo 2
onKeyUp="document.getElementById(this.id).value=document.getElementById(this.id).value.toUpperCase()"
Convertir string latin
convert(cast(convert(b.tutor using latin1) as binary) using utf8) AS tutor,
"<span style='text-transform: uppercase;'>".((htmlentities($nombre))."</span>";
CREATE INDEX dx_fecha ON asignacion_horario (fecha);
Fondo hoja membretada
<style>
body {
background-image: url('https://tsgsistema.com/images/fondoHojaMembretada.png');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
</style>
tamaño es 820 x 1139
Codigo cmd para hacer pem y ser de sello
x509 -inform DER -outform PEM -in aaa010101aaa_csd_01.cer -pubkey –out aaa010101aaa_csd_01.cer.pem
pkcs8 –inform DER –in aaa010101aaa_csd_01.key –passin pass:a0123456789 –out aaa010101aaa_csd_01.key.pem
* Para leer el certificado e incrustarlo en el XML
x509 –text –in aaa010101aaa_csd_01.cer.pem
Zona Horario en php
define('TIMEZONE', 'America/Mexico_City');
date_default_timezone_set('America/Mexico_City');
echo 'Zona horaria del servidor: ' . date_default_timezone_get();
echo 'Fecha y hora actual del servidor: ' . date('Y-m-d H:i:s');
para configurarlo en php.ini
date.timezone = "America/Mexico_City"
ALTER TABLE ti_persona_c CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
UPDATE ti_cliente_c SET TICLC_RAZON_SOCIAL = CONVERT(BINARY CONVERT(TICLC_RAZON_SOCIAL USING latin1) USING UTF8MB4);
Calcular cuantos dias faltan php
$fechaEntega2="2024-01-10";
$fecha_objetivo = new DateTime($fechaEntega2); // Fecha destino
$hoy = new DateTime(); // Fecha actual
$faltante="";
$diferencia = $hoy->diff($fecha_objetivo);
$faltante=$diferencia->days . " días.";
Mandar Correo con Libreria
//crear correo. poner contraseña .Farbe15- copiar codigo de carpeta phpmailer
// Incluir los archivos de PHPMailer
require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';
require 'PHPMailer-master/src/Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
// Configuración del servidor SMTP
$mail->isSMTP();
$mail->Host = 'mail.terminatorfumigaciones.com.mx'; // Servidor SMTP (ejemplo: Gmail)
$mail->SMTPAuth = true;
$mail->Username = 'soporte@terminatorfumigaciones.com.mx'; // Tu correo
$mail->Password = '.Farbe2025'; // Tu contraseña o App Password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
// Configuración del correo
$mail->setFrom('soporte@terminatorfumigaciones.com.mx', 'Terminator Fumigaciones');
$mail->addAddress('terminatorfumigacionestxt@gmail.com', 'Terminator');
$mail->Subject = 'Asunto del correo';
$mail->Body = $cuerpo;
$mail->isHTML(true);
// Enviar el correo
$mail->send();
echo 'Correo enviado con éxito.';
} catch (Exception $e) {
echo "Error al enviar el correo: {$mail->ErrorInfo}";
}
$ultimoDia = date("Y-m-t"); // Devuelve el último día del mes en formato YYYY-MM-DD
echo $ultimoDia;
Sesion que dure un año
<?php
// Duración de la sesión en segundos (1 año)
$lifetime = 365 * 24 * 60 * 60;
// Configurar la cookie de sesión para que dure 1 año
session_set_cookie_params($lifetime);
ini_set('session.gc_maxlifetime', 31536000);
session_start();
?>
// o en .htaccess
php_value session.gc_maxlifetime 31536000
php_value session.cookie_lifetime 31536000
poner el codigo al final de cada archivo
<script>
document.body.innerHTML = document.body.innerHTML
.replace(/Registrar Servicio/g, "Register Service")
.replace(/Prestamo/g, "Loan")
.replace(/Realizar Corte/g, "Make Cut")
.replace(/Tablero de Control/g, "Control Board");
</script>
formato moneda sin Redondear
number_format($Datos['importe'], 5, '.', ',')
Filtrar paginar
<style>
#pagination button {
padding: 4px 8px; /* más pequeño que el valor por defecto */
margin: 2px;
font-size: 12px;
border-radius: 4px;
border: 1px solid #ccc;
background-color: #f2f2f2;
cursor: pointer;
}
#pagination button:disabled {
background-color: #ddd;
font-weight: bold;
}
</style>
<table>
<tr>
<td>Buscar:</td>
<td>
<input type="text" id="myInput" style="width:400px" class='form-control' onkeyup="filterTable()" placeholder="Buscar...">
</td>
</tr>
</table>
<table border="1" class="hoverTable">
<thead>
<tr>
<th>#</th>
<th>Empresa</th>
<th>Contacto</th>
<th>Telefono</th>
<th>Celular</th>
<th></th>
<th></th><th></th>
</tr>
</thead>
<tbody id="tableBody">
<?php echo $v_proveedores?>
</tbody>
</table>
<div id="pagination"></div>
<script>
let currentPage = 1;
const rowsPerPage = 4;
let filteredRows = [];
function getFilteredRows() {
const input = document.getElementById("myInput").value.toUpperCase();
const rows = Array.from(document.getElementById("tableBody").getElementsByTagName("tr"));
if (!input) {
return rows;
}
return rows.filter(row => {
const cells = row.getElementsByTagName("td");
for (let cell of cells) {
const text = cell.textContent || cell.innerText;
if (text.toUpperCase().indexOf(input) > -1) {
return true;
}
}
return false;
});
}
function renderTablePage(page) {
const start = (page - 1) * rowsPerPage;
const end = start + rowsPerPage;
const rows = filteredRows;
rows.forEach((row, index) => {
row.style.display = (index >= start && index < end) ? "" : "none";
});
currentPage = page;
renderPagination();
}
function renderPagination() {
const pagination = document.getElementById("pagination");
pagination.innerHTML = "";
const totalPages = Math.ceil(filteredRows.length / rowsPerPage);
if (totalPages <= 1) return;
for (let i = 1; i <= totalPages; i++) {
const btn = document.createElement("button");
btn.innerText = i;
btn.onclick = () => renderTablePage(i);
if (i === currentPage) btn.disabled = true;
pagination.appendChild(btn);
}
}
function filterTable() {
const allRows = Array.from(document.getElementById("tableBody").getElementsByTagName("tr"));
filteredRows = getFilteredRows();
// Ocultar todas las filas primero
allRows.forEach(row => row.style.display = "none");
renderTablePage(1);
}
// Inicializar tabla al cargar
window.onload = () => {
filteredRows = getFilteredRows(); // carga todos al inicio
renderTablePage(1);
};
</script>
Imprimir generar pdf dompdf
require '../dompdf/autoload.inc.php';
use Dompdf\Dompdf;
// Crear una instancia de Dompdf
$dompdf = new Dompdf();
$dompdf->set_option('isRemoteEnabled', true);
// Definir el contenido HTML
$html = '<h1>Ejemplo de PDF</h1><p>Contenido generado dinámicamente.</p>';
$dompdf->loadHtml($html);
// Configurar el tamaño de papel y orientación
$dompdf->setPaper('A4', 'portrait');
// Renderizar el PDF
$dompdf->render();
// Mostrar el PDF en el navegador (sin descargar ni guardar en el servidor)
$dompdf->stream('documento.pdf', ['Attachment' => false]);
exit;
SET @i := 0;
UPDATE modulos
SET id_modulo = (@i := @i + 1);
Cambiar Fuente
entrar en esta liga https://fonts.google.com/
buscar la fuente pulsar get font y pulsar "get embed font"
copiar liga de css y crear una clase
ejemplo
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Oswald:wght@200..700&display=swap" rel="stylesheet">
<style>
.oswald {
font-family: "Oswald", sans-serif;
font-optical-sizing: auto;
font-weight: <weight>;
font-style: normal;
}
</style>
<div class='oswald'></div>
$archivo = 'ruta/del/archivo.txt';
if (file_exists($archivo)) {
if (unlink($archivo)) {
echo "Archivo eliminado correctamente.";
} else {
echo "No se pudo eliminar el archivo.";
}
} else {
echo "El archivo no existe.";
}
Exportar imagen
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<button id="exportBtn" class="icono" title="Exportar como imagen">Exportar</button>
<div id="contenedor">
<div style="width:600px">
<table width="600" id="miTabla" class="table table-bordered table-hover table-striped" >
</table>
</div>
</div>
<script>
document.getElementById('exportBtn').addEventListener('click', function () {
const elemento = document.getElementById('miTabla');
// Opciones importantes:
// - scale: 2 => mejora resolución final (retina)
// - backgroundColor: null => si quieres conservar transparencia; usa 'white' para fondo blanco
html2canvas(elemento, { scale: 2, backgroundColor: 'white', useCORS: true })
.then(canvas => {
// Crear enlace de descarga
const link = document.createElement('a');
link.download = 'tabla.png';
link.href = canvas.toDataURL('image/png');
link.click();
})
.catch(err => {
console.error('Error generando imagen:', err);
alert('No se pudo generar la imagen. Revisa consola.');
});
});
</script>
Sumar Dias a una fecha en mysql
SELECT DATE_ADD('2025-02-01', INTERVAL 5 DAY) AS nueva_fecha;