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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.