Jump to content

ryancooper

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ryancooper's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I updated the code in my second post as im unable to edit the original. Sorry, updated code below. Im trying only allow 4 words or spaces within quotes... i can do it for a simple string, but not only within quotes. $data = 'Hello World "This is a test string! Jack and Jill went up the hill."'; $halt = 'String had more than 4 spaces.'; $arr = explode('"', $data); if (substr_count($arr, ' ') >= 4) { $data = implode('"', $arr); $data = $halt;
  2. Pretty close. preg_match('/<body>(.*?)<\/body>/s', $content, $matches);
  3. Pretty close, except i need it to only look inside exploded quotes... so: Hello World "This is a test string! Jack and Jill went up the hill." would change the string to the halt. Hello World "This is a test!" would not change because there is only three spaces within the quotes.
  4. Sorry, updated code below. Im trying only allow 4 words or spaces within quotes... i can do it for a simple string, but not only within quotes. $data = 'Hello World "This is a test string! Jack and Jill went up the hill."'; $halt = 'String had more than 4 spaces.'; $arr = explode('"', $data); if (substr_count($arr, ' ') >= 4) { $data = implode('"', $arr); $data = $halt;
  5. I keep having trouble with exploded arrays, every function i go to use within the exploded quotes requires a string not an array. Below im trying to count the spaces and if there are four or more change the data string to the halt string. The problem is most of the functions require a string, is there another way to only count the space characters within quotes without exploding the quotes? $data = 'Hello World This is a test string!'; $halt = 'String had more than 4 spaces.'; $arr = explode('"', $data); if (substr_count($arr, ' ') >= 4) { $data = implode('"', $arr); $data = $halt;
  6. Awesome, i can actually use this is a different instance, i appreciate it! Thank you!!!
  7. I'm not sure why, but using strtoupper doesnt seem to work when replacing unset? Any idea why?
  8. I copied the code again, same problem, however the attached code runs fine. That works perfect, thanks so much for your help, you made it seem easy, ive had quite a few people try and not be able to help so i really appreciate it. Could i change unset($quote[1]); to strtoupper($quote[1]); to say make the second word all uppercase?
  9. Yeah i think your's is close im getting unexpected T_CONSTANT_ENCAPSED_STRING for your regex, im trying to figure out what quote is unescaped...
  10. Thanks for your response, ive been working all week on a solution but usually people dont understand what im trying to do... There is only one set of quotes in the string, and there is always text before and after the quotes. I've tried messing with Regex a bit, the basics are easy enough but when you get it the more complex expressions its really overwhelming... It would work to split the matched string by spaces though, i assume thats what you mean.
  11. I'm using the code below to on echo certain words based on their index/key value, this works fine however, im trying to only do this in exploded quotes... the problem is, exploding quotes turns the portion into an array which cant be passed to str_word_count... how can i do the same thing only inside quotes. So that hello world "this is a test" would become: Hello World This [0] => Is [1] => a [2] => Test [3] Im trying to always remove say the 4th word in quotations, or maybe the 3rd and 4th, whatever i want to omit i leave out from the echo, so echo $data[0].' '.$data[3].'; would output "This Test" omitting "Is A" $data = 'hello world "this is a test"'; $data = str_word_count($data, 1); echo $data[1].' '.$data[2].' '.$data[0];
  12. if (stripos($data, 'numbers') !== false) { $data = preg_replace('/\d/', '', $data); } This is the code i was able to come up with some help from the people at sof... It's supposed to remove the numbers mixed in characters in between quotations if a keyword is found. In the example above that word is numbers, however this example removes all numbers from the entire string and if i change the regex to '/"\d+"/' to only remove numbers matched within quotes it no longer works. This may or may not need to be moved, i realize the regex maybe the problem, however i wasnt sure if the quotation section needed to be defined as a new object to have the preg_replace applied to and the reinserted back in place, thus leaving the numbers not in quotations alone. A example would be: I am 13 as of today, what an unlucky number. "B1D3AY" Would be I am 13 as of today, what an unlucky number. "BDAY" Stripping the 1 and 3 from BDAY but leaving the 13 not inside quotations.
  13. The main issue is with strip_tags if i post. Grrr <-- Yeah i was super frustrated there. <b>I'm better now.</b> strip_tags removes everything but Grr since it sees the <-- as a comment bracket and strips everything from there on in...
  14. Okay, i wasnt sure what section to post in but im leaning toward this one so here it is. I am trying to find the most efficient way to remove not all HTML but some, strip_tags lets you define allowable tags, i need to only remove certain ones, the problem is if i have <-- or << then strip_tags removes them with the rest of the HTML, Is there a way to only take tags that were opened and closed? Or in other words valid HTML? Or would i have to create a regex for every common HTML tag to have it stripped on its own? I'm new to PHP so the only work around ive been able to use is to str_replace every group of characters into a number, then strip_tags, then the number back into the associated characters... i realize this is a rigged work around and thats why im looking for something more efficient especially since any undefined groups get pulled. One option which im not even sure is possible would be to match any HTML and if its a letter following the bracket have it stripped the only exception would be to also taking out / in closing brackets, this way <a herf would be stripped <b> </b> would both be stripped, so if the bracket is followed by any non A-Z character besides / it will be stripped, but if any bracket is followed by another bracket or various other symbols that arent used it will be left alone.
×
×
  • 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.