salman_ahad@yahoo.com Posted October 21, 2009 Share Posted October 21, 2009 I am checking for delimiter (.!?) and if there is a " after a sentence then it should neglect and start from next sentence I am splitting into two sentences "This is first sentence." This is second. When I split it is taking the second sentence as " This is second sentence. Which I dont want Help please Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/ Share on other sites More sharing options...
MadTechie Posted October 22, 2009 Share Posted October 22, 2009 like this ? <?php $string = '"This is first sentence." This is second. " This is second sentence. Which I dont want "This is first sentence." Blar. " This is second sentence. Which I dont want '; preg_match_all('/".*?[.!?]"(.*?$)/sm', $string, $result, PREG_PATTERN_ORDER); $result = $result[1]; var_dump($result); ?> array(2) { [0]=> string(16) " This is second." [1]=> string(6) " Blar." } Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-941619 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 22, 2009 Author Share Posted October 22, 2009 What is this code '/".*?[.!?]"(.*?$)/sm' Also what does preg_match_all does Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-941630 Share on other sites More sharing options...
MadTechie Posted October 22, 2009 Share Posted October 22, 2009 What is this code '/".*?[.!?]"(.*?$)/sm' Its a regular expression Also what does preg_match_all does preg_match_all uses the regular expression to capture all of the results into an array see manual preg_match_all the regular expression i wrote does the following matches a " then anything up until a . or ! or ? followed by a " then captures everything to the end of the line Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-941657 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 22, 2009 Author Share Posted October 22, 2009 @MadTechie Lets go over with the code... $para = $_POST['para']; //Getting para in variable } $sent = split('[.!?]',$para); //Split based on .!? foreach ($sent as $content) //for all the arrays, sentences(sent)...do this { if (strlen($content)<=115) //some condition... echo $content.'.<br />'; Now this code is resulting is few sentences starting with \"We need to eliminate this by checking sentences not starting with QUOTE PLEASE HELP WITH CODE Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-941685 Share on other sites More sharing options...
MadTechie Posted October 22, 2009 Share Posted October 22, 2009 I have already posted a solution.. what's wrong with it ? Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-941758 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 22, 2009 Author Share Posted October 22, 2009 Your solution is not working..it was giving an error. I think there is an in the regular expression, it is not giving the desired result. Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-942210 Share on other sites More sharing options...
MadTechie Posted October 22, 2009 Share Posted October 22, 2009 Your solution is not working..it was giving an error. What error ? I think there is an in the regular expression, it is not giving the desired result. What was it doing or not doing ? Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-942389 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 23, 2009 Author Share Posted October 23, 2009 @madTechie It did not work for some reason. Could you please explain me your regular expression in detail please Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-942615 Share on other sites More sharing options...
MadTechie Posted October 23, 2009 Share Posted October 23, 2009 It did not work for some reason. Explain what you mean by "did not work" Could you please explain me your regular expression in detail please I did the regular expression i wrote does the following matches a " then anything up until a . or ! or ? followed by a " then captures everything to the end of the line What part do you need more detail on? Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-942715 Share on other sites More sharing options...
.josh Posted October 23, 2009 Share Posted October 23, 2009 MadTechie this is your final warning. If you cannot learn to be psychic I am demoting you. Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-942828 Share on other sites More sharing options...
RickXu Posted October 23, 2009 Share Posted October 23, 2009 MadTechie this is your final warning. If you cannot learn to be psychic I am demoting you. This is a joke, right? People here have seen how much help MadTechie has offered over the past few year. The problem is that some people never understand or even bother to learn how to ask for help. Coding wise, if you don't debug, or simply put, if you don't read your error messages and post back to the person who has been trying to help you with the returned errors. What are you expecting? I feel sorry for myself wasting my very virgin post... Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-942871 Share on other sites More sharing options...
MadTechie Posted October 23, 2009 Share Posted October 23, 2009 Ahh okay.. It did not work for some reason. I think the problem is a syntax error on one of the lines of code or maybe the logical error, Could you please explain me your regular expression in detail please regular expressions, also referred to as regex or regexp, provide a concise and flexible means for identifying strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification. The following examples illustrate a few specifications that could be expressed in a regular expression: * the sequence of characters "car" in any context, such as "car", "cartoon", or "bicarbonate" * the word "car" when it appears as an isolated word * the word "car" when preceded by the word "blue" or "red" * a dollar sign immediately followed by one or more digits, and then optionally a period and exactly two more digits Regular expressions can be much more complex than these examples. Now /".*?[.!?]"(.*?$)/sm Matches the character " literally " then Match any single character .*? Between zero and unlimited times, as few times as possible, expanding as needed (lazy) *? then Match a single character present in the list .!? [.!?] then Match the character " literally " then Match the regular expression below and capture its match into backreference number 1 (.*?$) then Match any single character .*? Between zero and unlimited times, as few times as possible, expanding as needed (lazy) *? Assert position at the end of a line (at the end of the string or before a line break character) $ SM: dot matches newline; ^ and $ match at line breaks Hope that helps I feel sorry for myself wasting my very virgin post... LMAO Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-942874 Share on other sites More sharing options...
.josh Posted October 23, 2009 Share Posted October 23, 2009 MadTechie this is your final warning. If you cannot learn to be psychic I am demoting you. This is a joke, right? No joke. Even though a lot of people can't be bothered with giving details about their problem or following advice, etc.. the customer is nonetheless always right. Therefore we expect all staff members to be psychic, in order to cater to this. That way, users not posting relevant stuff is no longer an issue. Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-942900 Share on other sites More sharing options...
akitchin Posted October 23, 2009 Share Posted October 23, 2009 MadTechie this is your final warning. If you cannot learn to be psychic I am demoting you. This is a joke, right? No joke. Even though a lot of people can't be bothered with giving details about their problem or following advice, etc.. the customer is nonetheless always right. Therefore we expect all staff members to be psychic, in order to cater to this. That way, users not posting relevant stuff is no longer an issue. in fact, there is an administration thread with good books about mastering psychic clairvoyance. i recommend "Psychic Reading in 30 Days" from O'Reillly. great read. best part is, if you've been paying attention, roughly halfway through you can already surmise what the rest of the book contains using the skills you've learned! Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-943152 Share on other sites More sharing options...
MadTechie Posted October 23, 2009 Share Posted October 23, 2009 in fact, there is an administration thread with good books about mastering psychic clairvoyance. i recommend "Psychic Reading in 30 Days" from O'Reillly. great read. best part is, if you've been paying attention, roughly halfway through you can already surmise what the rest of the book contains using the skills you've learned! The 2nd edition comes with a cheat sheet, I have read that i have no idea what 99% of it mean, I started reading it but you can't really skip anything, So I am still on the intro, about the how they used a super computer with MPR (multivariate pattern recognition) to map the regions of the brain, but I found it pretty dry, ie Researchers have used mathematical models to show that while our brains may be wired differently, a comparable pattern of neural activity and function can be observed between two brains when exposed to similar sensory input. Which may not seem like a big deal; after all, arriving at the same idea or solution as a colleague isn't a rare occurrence. But when you consider the sheer number of neurons and networks involved in the process, there would seem to be little chance for us to come up with the same answer at all. Even in a "network of 1,000 neurons, where each neuron can be connected to any other, there are a million possible contacts between any two neurons and consequently an unimaginably large number of possible networks," say researchers Raoul-Martin Memmesheimer and Marc Timme. "Each combination can have either an inhibiting or an activating effect on the downstream neuron and, in addition to this, can differ in its intensity and reaction time." I mean, I can't even read minds while in a 10 meter radios (which is the easiest one), akitchin, did you try or have any luck with CV's post about Advanced Jedi Mind Tricks is way to advanced for me.. Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-943217 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 24, 2009 Author Share Posted October 24, 2009 Respected MadTechie <?php $string = "These are our sentences." This is great. "You are the best!" You can do it.; preg_match_all('/" your expression/sm', $string, $result, PREG_PATTERN_ORDER); .... foreach ($result as $result2){ echo $result2. '<br \>'; } ?> my expected result: These are our sentences This is great You are the best You can do it I hope you could help me with this now. I cannot explain my question more clearer than this! Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-943250 Share on other sites More sharing options...
.josh Posted October 24, 2009 Share Posted October 24, 2009 wtf I feel like I'm tastin' the rainbow. Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-943327 Share on other sites More sharing options...
MadTechie Posted October 24, 2009 Share Posted October 24, 2009 That doesn't match your own logic, but this should get the results you want <?php #$string = '"This is first sentence." This is second.'; //Match 2 #$string = '" This is second sentence. Which I dont want'; //Match 0 $string = '"These are our sentences." This is great. "You are the best!" You can do it.'; //Match 4 preg_match_all('/(?<=")\s*(.*?)[.!?]\s*(?="|$)/sm', $string, $result, PREG_PATTERN_ORDER); $result = $result[1]; foreach ($result as $result2){ echo $result2. '<br \>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-943457 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 25, 2009 Author Share Posted October 25, 2009 Thanks @MadTechie Almost done ! this is my code -------------- preg_match_all('/(?<=")\s*(.*?)[.!?]\s*(?="|$)/sm', $para, $result, PREG_PATTERN_ORDER); $result = $result[1]; foreach ($result as $result2){ if (empty($result2)) continue; else { if (strlen($result2)<=115) echo $result2.'.<br />'; else echo substr($result2,0,115). '...Read More.<br />'; } } // Lets say I am accepting a big paragraph. But there are only 3 output sentences. How can we change just enough to output all the sentences...?? Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-943787 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 26, 2009 Author Share Posted October 26, 2009 It is not solved, but I am closing it. Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-944353 Share on other sites More sharing options...
MadTechie Posted October 26, 2009 Share Posted October 26, 2009 I have no idea what this means // Lets say I am accepting a big paragraph. But there are only 3 output sentences. How can we change just enough to output all the sentences...?? Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-944356 Share on other sites More sharing options...
salathe Posted October 26, 2009 Share Posted October 26, 2009 I hope you could help me with this now. I cannot explain my question more clearer than this! Please try. What value of $para gives you only three sentences and how many are you expecting? Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-944359 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 26, 2009 Author Share Posted October 26, 2009 If we give a big article for say. It will obviously have many sentences. I am splitting my article (paragraph) into sentences based on delimiters (.!?) By using the regular expression of MadTechie I am seeing only three sentences are formed in any large amount of paragraph I submit. I should get rest of the sentences till the paragraph finish right?? But the output is only 3 sentences using MadTechie's expression. Any solution?? Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-945052 Share on other sites More sharing options...
MadTechie Posted October 27, 2009 Share Posted October 27, 2009 WTF.. wait one second.. the RegEx I wrote are to your specification that's is logically flawed, (as I have stated) and I still have no idea what your trying to do, as your logic doesn't make logical sense! -Techie Out Quote Link to comment https://forums.phpfreaks.com/topic/178545-chech-a-string-for-double-quotes/#findComment-945088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.