Jump to content

Grabbing quotes from a text?


RobboSan

Recommended Posts

Hi there

 

 

I was wondering if anyone could help me with a program I'm trying to write.

 

What I want it to do is: have a user input text (through a form)

                                Then have all the quotes ("lalala") from that text displayed

 

                          ex. This is the text that "was entered" in the form.

 

            All I want to show up after the user enters the text is: "was entered"

 

I have some work on it done but I'm too new at PHP to even know if it is worth going in the direction I'm heading in.

If anyone know an easy way to do this it would be greatly appreciated. If not, sorry to bother you

Link to comment
https://forums.phpfreaks.com/topic/80533-grabbing-quotes-from-a-text/
Share on other sites

Regular expressions are your friend:

 

<?php
$str = 'This is the text that "was entered" in the form. More "text entered".';
preg_match_all('|"(.*?)"|',$str,$matches);
foreach($matches[1] as $v){
echo 'Quote: '.$v.'<br />';
}
?>

 

Regular expressions allow you to match/find/replace specific text against general patterns. There's a subform here which might help you understand a bit about them, or you can google.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.