pastebin

Paste Search Dynamic
Recent pastes
s2scan
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. function s2scan(&$str, $what)
  6. /* Often want a fn like fgets but for a string(ie containing linebreaks) rather than an input stream.
  7.   Might use sscanf, but it doesn't quite allow doing the required thing.
  8.   So my s2scan can be applied to a "string of lines", to just peel off 1 line at a time(parm $initial), and reducing $str by that line each time.  In this case $what==whatever newline char ("\r\n" in case of randcand (plaintxt) blog file)
  9.   Note-- $what char(s) INCLUDED in return string.  Also- the last "line" in $str not need be $what-terminated
  10.   (note also $y and all the params are local symbols, by the general rules of Php)
  11.   I've made s2scan a little more general (but not mutli-args)       */
  12. { $initial=($y=strpos($str, $what))?substr($str, 0, $y+strlen($what)):$str;       // +strlen($what) added, to include the $what str in the result
  13.    $str=$y?substr($str, $y+strlen($what)):'';
  14.    return  $initial;    }
  15.  
  16. function prvw_fixusmsg($usmg) {
  17.  $usmg2 = "";
  18. //while($usmg != "") {
  19.    $tmp=s2scan($usmg, "\n");
  20.    if($tmp[strlen($tmp)-1]==="\n")
  21.      $usmg2 .= substr($tmp, 0, strlen($tmp)-2) . "\\r\\n";
  22.    else  $usmg2 .= $tmp;
  23.  //}
  24.  return $usmg2;
  25. }
  26.  
  27.  
  28. function substchar($str, $tgtstr, $chgto) {
  29.  $tgtlen = strlen($tgtstr);
  30.  $rsult = "";
  31.  while($str != "") {
  32.   $tmp=s2scan($str, $tgtstr);
  33.  }
  34. }
  35.  
  36.  
  37.  
  38. $test0 = "This is a test string.\nwith some newlines\nOK?\nSure you're Ok with that?\nMmmm.....";
  39. $test1 = prvw_fixusmsg($test0);
  40. echo "\$test1=|$test1|      \$test0=|$test0|";
  41. ?>
Parsed in 0.022 seconds