Note that there are some explanatory texts on larger screens.

plurals
  1. POReplace Spaces within "", preg_replace php
    primarykey
    data
    text
    <p>I have some strings like this:</p> <blockquote> <p>i: 11;a:5: {s:2:"id";s:4:"1097";s:5:"iName";s:12:"Ovo de Andre";s:10:"dropChance";s:4:"2000";s:4:"type"; i:1;s:5: "kName"; s:12: "Ovo de Andre";</p> </blockquote> <p>And, I'd like to know how I could replace that string: "Ovo de Andre" to something like this:</p> <blockquote> <p>"Ovo_de_Andre", but it can't change any spaces that could be out "".</p> </blockquote> <p>I tried:</p> <blockquote> <p><em>$string = preg_replace('/"(.</em>?)\s(.<em>?)"/m', '"$1_$2"', $string);</em></p> </blockquote> <p>But it just replaces the first space, then the string looks like this:</p> <blockquote> <p>i: 11;a:5: {s:2:"id";s:4:"1097";s:5:"iName";s:12:"Ovo_de Andre";s:10:"dropChance";s:4:"2000";s:4:"type"; i:1;s:5: "kName"; s:12: "Ovo_de Andre";</p> </blockquote> <p>I know I could use a while to check it, but it'd be problematic to performance and I think it'd would be redundant.</p> <p>Additionally, I want to know how could it be to make the same, but rather than replacing spaces within "", replace those out, without change spaces within "".</p> <p>Thanks in advance.</p> <hr> <p>I have this link that makes something similar but I couldn't manage what changing to make it reach what i want: <a href="https://stackoverflow.com/questions/4643442/using-preg-replace-to-replace-all-occurrences-in-php">Using preg_replace to replace all occurrences in php</a>.</p> <p>Here is the full data, I separeted it in strings to test one by one looking for errors that were there.</p> <blockquote> <blockquote> <p>$string = 'a:16:{'; $string .= ' i:0;a:5:{s:2:"id";s:4:"1113";s:5:"iName";s:5:"Drops";s:10:"dropChance";s:4:"7500";s:4:"type";i:1;s:5:"kName";s:5:"Drops";}'; $string .= 'i:1;a:5:{s:2:"id";s:4:"1585";s:5:"iName";s:11:"Mime Monkey";s:10:"dropChance";s:4:"7000";s:4:"type";i:1;s:5:"kName";s:11:"Mime Monkey";}'; $string .= 'i:2;a:5:{s:2:"id";s:4:"1027";s:5:"iName";s:7:"Raptice";s:10:"dropChance";s:4:"7000";s:4:"type";i:1;s:5:"kName";s:7:"Raptice";}'; $string .= 'i:3;a:5:{s:2:"id";s:4:"1002";s:5:"iName";s:6:"Poring";s:10:"dropChance";s:4:"7000";s:4:"type";i:1;s:5:"kName";s:6:"Poring";}'; $string .= 'i:4;a:5:{s:2:"id";s:4:"1767";s:5:"iName";s:8:"Deviling";s:10:"dropChance";s:4:"5000";s:4:"type";i:2;s:5:"kName";s:8:"Deviling";}'; $string .= 'i:5;a:5:{s:2:"id";s:4:"1767";s:5:"iName";s:8:"Deviling";s:10:"dropChance";s:4:"5000";s:4:"type";i:2;s:5:"kName";s:8:"Deviling";}'; $string .= 'i:6;a:5:{s:2:"id";s:4:"1766";s:5:"iName";s:8:"Angeling";s:10:"dropChance";s:4:"5000";s:4:"type";i:2;s:5:"kName";s:8:"Angeling";}'; $string .= 'i:7;a:5:{s:2:"id";s:4:"1766";s:5:"iName";s:8:"Angeling";s:10:"dropChance";s:4:"5000";s:4:"type";i:2;s:5:"kName";s:8:"Angeling";}'; $string .= 'i:8;a:5:{s:2:"id";s:4:"1004";s:5:"iName";s:6:"Zangão";s:10:"dropChance";s:4:"3500";s:4:"type";i:1;s:5:"kName";s:6:"Zangão";}'; $string .= 'i:9;a:5:{s:2:"id";s:4:"1236";s:5:"iName";s:12:"Ovo de Andre";s:10:"dropChance";s:4:"3000";s:4:"type";i:1;s:5:"kName";s:12:"Ovo de Andre";}'; $string .= 'i:10;a:5:{s:2:"id";s:4:"1076";s:5:"iName";s:9:"Esqueleto";s:10:"dropChance";s:4:"3000";s:4:"type";i:1;s:5:"kName";s:9:"Esqueleto";}'; $string .= 'i:11 ;a:5: {s:2:"id";s:4:"1097";s:5:"iName";s:12:"Ovo de Andre";s:10:"dropChance";s:4:"2000";s:4:"type";i:1;s:5:"kName";s:12:"Ovo de Andre";}'; $string .= 'i:12;a:5:{s:2:"id";s:4:"1051";s:5:"iName";s:14:"Besouro-Ladrão";s:10:"dropChance";s:4:"2000";s:4:"type";i:1;s:5:"kName";s:14:"Besouro-Ladrão";}'; $string .= 'i:13;a:5:{s:2:"id";s:4:"1183";s:5:"iName";s:16:"ChonChon Raivoso";s:10:"dropChance";s:4:"1500";s:4:"type";i:1;s:5:"kName";s:16:"ChonChon Raivoso";}';<br> $string .= 'i:14;a:5:{s:2:"id";s:4:"1011";s:5:"iName";s:8:"ChonChon";s:10:"dropChance";s:4:"1500";s:4:"type";i:1;s:5:"kName";s:8:"ChonChon";}'; $string .= 'i:15;a:5:{s:2:"id";s:4:"1784";s:5:"iName";s:5:"Stapo";s:10:"dropChance";s:4:"1000";s:4:"type";i:1;s:5:"kName";s:5:"Stapo";}'; $string .= '}';</p> </blockquote> </blockquote> <p>If looked carefully you'll notice in the lines i:0 and i:11 of the vector some spaces between the data that shows what line number and size of data exists.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload