snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#47930

MySQL

Reemplazar con MySQL

update alumnos set nombre = replace(nombre, '?', 'Ñ');
https://snipt.net/embed/521366309f97f120d474067370dcd5ac/
https://snipt.net/raw/521366309f97f120d474067370dcd5ac/
521366309f97f120d474067370dcd5ac
mysql
MySQL
1
2014-04-22T20:40:38
True
False
Oct 02, 2012 at 12:51 PM
/api/public/snipt/47930/
reemplazar-con-mysql
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">update</span> <span class="n">alumnos</span> <span class="kt">set</span> <span class="n">nombre</span> <span class="o">=</span> <span class="k">replace</span><span class="p">(</span><span class="n">nombre</span><span class="p">,</span> <span class="s1">&#39;?&#39;</span><span class="p">,</span> <span class="s1">&#39;Ñ&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
caracteres, mysql, reemplazar
#36654

JavaScript

Reemplazar valores

1
2
3
4
5
6
function cambiar(){
  //Cadena original
  var texto = $("#titulo").val();
  texto = texto.replace("¿", "&iquest;");
  $("#titulo").val(texto);
}
https://snipt.net/embed/8e90cc8a066a55b042deeef9b6e76970/
https://snipt.net/raw/8e90cc8a066a55b042deeef9b6e76970/
8e90cc8a066a55b042deeef9b6e76970
js
JavaScript
6
2014-04-20T19:37:17
True
False
/api/public/snipt/36654/
reemplazar-valores
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">cambiar</span><span class="p">(){</span> </span><span id="L-2"><a name="L-2"></a> <span class="c1">//Cadena original</span> </span><span id="L-3"><a name="L-3"></a> <span class="kd">var</span> <span class="nx">texto</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#titulo&quot;</span><span class="p">).</span><span class="nx">val</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">texto</span> <span class="o">=</span> <span class="nx">texto</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s2">&quot;¿&quot;</span><span class="p">,</span> <span class="s2">&quot;&amp;iquest;&quot;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#titulo&quot;</span><span class="p">).</span><span class="nx">val</span><span class="p">(</span><span class="nx">texto</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
jquery, reemplazar
#11518

PHP

Reemplazar caracteres no estandares

1
2
3
<?php
   strtr($cadena, "àáâãäåÁèéêëÉìíîïÍòóôõöÓùúûüÚñÑ", "aaaaaaAeeeeEiiiiIooooOouuuuUnN");
?>
https://snipt.net/embed/d3b49089247842bea8fe83d0bb81e40e/
https://snipt.net/raw/d3b49089247842bea8fe83d0bb81e40e/
d3b49089247842bea8fe83d0bb81e40e
php
PHP
3
2014-04-14T16:46:40
True
False
/api/public/snipt/11518/
reemplazar-caracteres-no-estandares
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">strtr</span><span class="p">(</span><span class="nv">$cadena</span><span class="p">,</span> <span class="s2">&quot;àáâãäåÁèéêëÉìíîïÍòóôõöÓùúûüÚñÑ&quot;</span><span class="p">,</span> <span class="s2">&quot;aaaaaaAeeeeEiiiiIooooOouuuuUnN&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
acentos, caracteres, reemplazar
#5442

PHP

Reemplazar variable en cadena

1
2
3
4
5
<?php     
  $valor = "* bullet";
  $nuevo_valor = str_replace ("*", "&bull; ", $valor);      
  echo $nuevo_valor;
?>
https://snipt.net/embed/a23bf332fa8db875b83cd77aca580a3c/
https://snipt.net/raw/a23bf332fa8db875b83cd77aca580a3c/
a23bf332fa8db875b83cd77aca580a3c
php
PHP
6
2014-04-20T19:37:21
True
False
/api/public/snipt/5442/
reemplazar-variable-en-cadena
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> <span class="nv">$valor</span> <span class="o">=</span> <span class="s2">&quot;* bullet&quot;</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$nuevo_valor</span> <span class="o">=</span> <span class="nb">str_replace</span> <span class="p">(</span><span class="s2">&quot;*&quot;</span><span class="p">,</span> <span class="s2">&quot;&amp;bull; &quot;</span><span class="p">,</span> <span class="nv">$valor</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">echo</span> <span class="nv">$nuevo_valor</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
reemplazar
#681

PHP

Saltos de línea en textarea

1
2
3
<?php
   str_replace("\n", "<br>", $row['contenido']);
?>
https://snipt.net/embed/91f0f99e297e03921d5b5f7b2d7e2bbf/
https://snipt.net/raw/91f0f99e297e03921d5b5f7b2d7e2bbf/
91f0f99e297e03921d5b5f7b2d7e2bbf
php
PHP
3
2014-04-20T19:37:29
True
False
/api/public/snipt/681/
saltos-de-linea-en-textarea
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> <span class="nb">str_replace</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">,</span> <span class="s2">&quot;&lt;br&gt;&quot;</span><span class="p">,</span> <span class="nv">$row</span><span class="p">[</span><span class="s1">&#39;contenido&#39;</span><span class="p">]);</span> </span><span id="L-3"><a name="L-3"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
linea, reemplazar, saltos