stripslashes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dorky
Forum Newbie
Posts: 9
Joined: Sat Jun 13, 2009 10:22 am

stripslashes

Post by Dorky »

i just cannot seem to figure out how to remove slashes from the first loop. no matter how i implement striplashes it will remove the text preceding the apostrophe that
is causing the slash.

Code: Select all

 
<?php
 
$pspell_link = pspell_new("en");
if(isset($_GET['text'])) {
$words = stripslashes($_GET['text']) ; }
echo  "<form method='get' action='spell.php'>";
 
 
if (isset($_GET['0'])) echo "0";
 { 
foreach($_GET as $key0 => $marker)   
  { 
   $value = split('[ ]', $marker );  
   $value0[] = $value[0] ; $value1[] = $value[1] ;  echo "Value : |0| $value0 |1|  $value1 |Key| $key0 <hr>";
   echo "Print Value Stage 1:";    print_r($value0); print_r($value1); echo "<hr>"; 
  }
$print = str_replace( $value0 , $value1 , $words ); 
 
 }
 
 
if(!isset($_GET['0'])) 
 {
 $print = $words; 
 }
 
 
 
 
 
 
 
if (isset($_GET['check'])) 
 { echo "<b><i> $words </i></b><hr>";
  $string = split('[ ]', $words); foreach($string as $key1 => $word)  
if (!pspell_check($pspell_link, $word)) 
  { 
   echo "<hr><b><i>$word</i></b><br>"; $suggestions = pspell_suggest($pspell_link, $word); 
foreach($suggestions as $key2 => $suggestion) 
   {  
    $send = "$word $suggestion";   echo "<input type='checkbox' name='$key1' value='$send'>$suggestion<br>"; 
   }
  }
 }  
 
 
echo "<hr><textarea name='text'class='textarea' type='text/plain' rows='15' cols='40'>$print</textarea><hr>"; 
if(!isset($_GET['check'])) { echo "<button name='check' value='check check' type='submit'>Check Spelling</button>"; }
if(isset($_GET['check'])) { echo "<button name='done' value='done done' type='submit'>Done</button>"; }
echo "</form>"; 
 
unset($print);
 
?>
 
 
 

further if you see any other part of this code you would like to comment on please do so.
Last edited by Dorky on Sat Jun 13, 2009 6:28 pm, edited 1 time in total.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: stripslashes

Post by Ollie Saunders »

Try:

Code: Select all

array_walk_recursive($_GET, 'stripslashes');
Dorky
Forum Newbie
Posts: 9
Joined: Sat Jun 13, 2009 10:22 am

Re: stripslashes

Post by Dorky »

ok im a tard. the stripslashes_deep was an attempt to try some advice not actually a part of my code.
i still as hard as i try do not understand functions or classes. they seem quite redundant and overkill.
if im wrong correct me. also i have attempted several time to implement them only to get hammered with errors.
but aside from that i have edited the code above to what i wrote and need help with. i did try the walk but
when i put it in i got some crap about my foreach not having a valid variable. so not only did it not work but it
recursively(pun) caused more problems. i do need help with this desperately though and out of 55 views on 3 forums
you are the only one brave enough to respond. thx much hope you write again.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: stripslashes

Post by Ollie Saunders »

OK. We'll get through this. In your clearest possible terms, what is this script supposed to do?
Dorky
Forum Newbie
Posts: 9
Joined: Sat Jun 13, 2009 10:22 am

Re: stripslashes

Post by Dorky »

this is a spell check. well supposed to be when its done
you can see the live version of where im at http://www.studio378d.com/spell.php
and really i need to just allow punctuation all together.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: stripslashes

Post by Ollie Saunders »

This may help you:

Code: Select all

$a = "monkey%dust pow wow"; 
var_dump(preg_split("/\b/", $a, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE));
It splits things into words but retains the punctuation.
Dorky
Forum Newbie
Posts: 9
Joined: Sat Jun 13, 2009 10:22 am

Re: stripslashes

Post by Dorky »

is this an example to play with or something intended to implement. and what is the breakdown, var_dump is just to display right?
Dorky
Forum Newbie
Posts: 9
Joined: Sat Jun 13, 2009 10:22 am

Re: stripslashes

Post by Dorky »

output=

array(7) { [0]=> string(6) "monkey" [1]=> string(1) "%" [2]=> string(4) "dust" [3]=> string(1) " " [4]=> string(3) "pow" [5]=> string(1) " " [6]=> string(3) "wow" }

it seems to apply the punctuation to each set of words. i can see this working if i understood the components.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: stripslashes

Post by Ollie Saunders »

var_dump() is just display, yes. Look up any functions you don't understand in the PHP manual.

You can use preg_split() as I showed with $_GET['text'] to get all the words and punctuation. You then want to spell-check the words. You can recombine it all back together with implode().
Dorky
Forum Newbie
Posts: 9
Joined: Sat Jun 13, 2009 10:22 am

Re: stripslashes

Post by Dorky »

well i do thank you for the attempt but after breaking this into each of its parts and examining them it still looks like more code then i have for the entire spell check just to pass punctuation would be needed. this would only break it apart, then i would need to make exception for each type of punctuation and still further put it back together all within loops. im sure there is a way to do this on less then 50 characters of code. and $_GET is not excepted in place of the $a, preg require a string. i need this to happen to the array or i would have to break it into a string then back to an array to finish the loop, WOW. but i do thank you.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: stripslashes

Post by Ollie Saunders »

after breaking this into each of its parts and examining them it still looks like more code then i have for the entire spell check just to pass punctuation would be needed.
Maintaining the punctuation isn't something you should do separately from spell-checking the words. It needs to be part of the same process, or some points if not throughout.

Possibly you're thinking of the computer as being able to interpret your intent for you. It can't. You have to tell it specifically the rules by which you want to break apart the text, examine it, provide options for misspelt words, present options for those misspellings, capture the user's choice, make changes according to the user's choices and recombine everything, all with the available functions the PHP provides and within the constraints of HTML. You have to do all of that.
this would only break it apart, then i would need to make exception for each type of punctuation and still further put it back together all within loops.
You have to determine what is a word from everything else. A regular expression pattern of /\w+/ will match words. You can use that with preg_match().
im sure there is a way to do this on less then 50 characters of code.
A highly idiomatic language such as Perl or J might be able to express this in a smaller amount of code. But that wouldn't necessarily make this any easier to write, in fact, probably harder.
$_GET is not excepted in place of the $a, preg require a string.
Yes. preg_split() will only split strings. You need to define how the array should become a string in order to be processed by preg_split().
i need this to happen to the array or i would have to break it into a string then back to an array to finish the loop, WOW.
Yep, you might have to do that.
Dorky
Forum Newbie
Posts: 9
Joined: Sat Jun 13, 2009 10:22 am

Re: stripslashes

Post by Dorky »

ok i was totaly mistaken about when the problem is occurring. this is the get in the address bar.

?0=hgfhg&text=hgfhg's&done=done+done
Dorky
Forum Newbie
Posts: 9
Joined: Sat Jun 13, 2009 10:22 am

Re: stripslashes

Post by Dorky »

<input type='checkbox' name='$key1' value='$send'>$suggestion
this is where it is happening duuuuuuu!

value='blablabla's'

whats wrong with that picture lol.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: stripslashes

Post by Ollie Saunders »

Right. You need to urlencode().
Dorky
Forum Newbie
Posts: 9
Joined: Sat Jun 13, 2009 10:22 am

Re: stripslashes

Post by Dorky »

tada yeah i figured that out pretty quick

Code: Select all

<?php
 
 
 
 
 
$pspell_link = pspell_new("en");
if(isset($_GET['text'])) {
$words = stripslashes($_GET['text']) ; }
echo  "<form method='get' action='spell.php'>";
 
 
if (isset($_GET['done'])) echo "0";
 { 
foreach($_GET as $key => $markers) 
  { $marker = rawurldecode($markers);
   $value = split('[ ]', $marker );  if(empty($value[0])) continue; if(empty($value[1])) continue;
   $value0[] = stripslashes($value[0]) ; $value1[] = stripslashes($value[1]) ;   
  } 
  echo "Print Value Stage 1:";    print_r($value0); print_r($value1); echo "<hr>"; 
 $print = str_replace( $value0 , $value1 , $words ); 
 }
 
 
 
if(!isset($_GET['done'])) 
 {
 $print = $words; 
 }
 
 
 
 
 
 
 
if (isset($_GET['check'])) 
 { echo "<b><i> $words </i></b><hr>";
  $string = split('[ ]', $words); foreach($string as $key1 => $word)  
if (!pspell_check($pspell_link, $word)) 
  { 
   echo "<hr><b><i>$word</i></b><br>"; $suggestions = pspell_suggest($pspell_link, $word); 
foreach($suggestions as $key2 => $suggestion) 
   { 
    $set = "$word $suggestion"; $send = rawurlencode($set); echo "<input type='checkbox' name='$key1' value='$send'>$suggestion<br> "; 
   }
  }
 }  
 
 
echo "<hr><textarea name='text'class='textarea' type='text/plain' rows='15' cols='40'>$print</textarea><hr>"; 
if(!isset($_GET['check'])) { echo "<button name='check' value='check check' type='submit'>Check Spelling</button>"; }
if(isset($_GET['check'])) { echo "<button name='done' value='done done' type='submit'>Done</button>"; }
echo "</form>"; 
 
unset($print);
 
?>
 
 
 
http://studio378d.com/spell.php
i would be honored if you had a test drive
Post Reply