Jump to content

rea|and

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rea|and's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I've added 2 patterns in your regex. One to match links, the other to match images. They are generic patterns, you could change the first with something more specific or add some other images extensions in the second. Try it $BBCode_Text=preg_replace('/(https?:\/\/(www)?)\S+|\S+\.(jpe?g|gif|png)|\S{'.$character_limit.'}(?=\S)/im', "$0 ", $BBCode_Text);
  2. Try this one: $pattern = '/<(a(?=[^>]+class=(\'|")Link(?:\\2))|span(?=[^>]+class=(\'|")Title(?:\\3)))[^>]+>(.*?)<\/\\1>/si'; preg_match_all($pattern, $result, $matches, PREG_SET_ORDER); foreach ($matches as $val) { echo "Tag: {$val[1]} - {$val[4]}<br />"; }
  3. Have you tried strip_tags? As second parameter it takes the allowable tags. Anyways if you want do it with regex try this one (I've modified Crayon Violent regexp adding a negative lookahead assertion): $content=preg_replace('/<\/?(?!input|textarea|select)[^>]*>/','',$content); In some cases it could have problems (html code within html comments ... casually I tried it against a page that had it).
  4. The whitespace is url-encoded as plus (+) so I guess you need to urlencode your "t.value" before passing it to json. Try to search urlencode in the js section of this forum.
  5. Hello, it's just a side issue, but you could rewrite it in this way: function countContains($string, $chars){ return preg_match_all('#[' . preg_quote($chars, '#') . ']#', $string, $matches); }
  6. Well, you could not hard-set your output within your regular expression. What I've told before is that using a conditional statement you will know in advance that your output will be "A" or "B" match, but you couldn't force your output to be "A", "B" or some thing else. You needs to work with a callback function to check & force your output.
  7. The syntax you are using is also a conditional statement; you can set two ways of matching a string in the same regexp. I.e. <?php # if a line starts w/ a number then match something, otherwise something else #(?(condition)true case|false case) $rex='/^(?(?=\d+)something|somethingelse)/m'; In a way you could set your output, but it is not its first aim. I'd keep on using a callback function to check your values.
  8. Try this code: <?php if (!preg_match("/^[a-z]+(,[a-z]+)+$/",$a)) { echo "no"; } ?>
  9. Back from lunch. That page you posted doesn't have any form tags, so regex can't match anything, instead I've modified the regexp to match no type att. or no quote cases, it seems to work: <pre><?php $form=array(); preg_replace_callback('/<form[^>]+action=("|\')(.+?)(\\1).+?<\/form>/is','cb_form',$text); function cb_form($mth){ global $form; preg_match_all('/<input(?(?=[^>]+type=)(?=[^>]+type=(?(?="|\')("|\')(?:text|password)(?:\\1)|(?:text|password))))[^>]+name=(?(?="|\')("|\')(.+?)(?:\\2)|(\S+))/is',$mth[0],$names); $form[$mth[2]]=($names[2][0]!='')?$names[3]:$names[4]; } print_r($form); ?></pre>
  10. What does that mean ? preg_match_all('/<input(?=[^>]+type="text")[^>]+name=("|\')(.+?)(\\1)/is',$mth[0],$names); this regex works only for type="text" , if i need for both "password" and "text" where i should i add ? It means that if some forms don't use quotes, like google, my code doesn't match the name fields. I could add if you need it, but for now let's check if it works. For the password problem I wrote a comment just below the preg_match_all line to explain how to add more than one attribute.
  11. Try something like this... I've tried this code only against the last page you've posted. Currently the regexps work only with double/single quotes (so not something like name=namefield). <pre><?php $text='your html code'; $form=array(); preg_replace_callback('/<form[^>]+action=("|\')(.+?)(\\1).+?<\/form>/is','cb_form',$text); function cb_form($mth){ global $form; preg_match_all('/<input(?=[^>]+type="text")[^>]+name=("|\')(.+?)(\\1)/is',$mth[0],$names); // for more than one type attribute // '/<input(?=[^>]+type="(?:text|hidden)")[^>]+name=("|\')(.+?)(\\1)/is' $form[$mth[2]]=$names[2]; } print_r($form); ?></pre>
  12. Try this regex: $rex='/("|\')(??:\\\\\\\\)*|.*?[^\\\\](?:\\\\\\\\)*)(?:\1|$)/s'; (It is a part of the other regex I posted yesterday) a little explanation $rex='/ ("|\') # match " or \' (?: (?:\\\\\\\\)*| # empty string or even number of slashes # like \\" or \\\\" or \\\\\\" etc # OR .*?[^\\\\](?:\\\\\\\\)* # non-empty string # ending with a even number of slashes # checking that the previous char is not a slash ) (?:\1|$) # match the first matching or the end of the string /xs';
  13. mmm, I've adjusted a class I wrote to parsing php code to work as request (I hope). It works as lococobra deduced. The result is an array where even elements contain html code and odd ones php code. I've made only few tests so I don't assure anything <?php include_once 'cl.split.code.php'; $code=file_get_contents('some_mixed_code.php'); $hcode = new lh_splitCode() ; $hcode->lh_splitting( $code ) ; print_r( $hcode->lh_get_code() ); ?> here the class: <?php /** * Andrea Ponzi, b 1.0, 23/07/2007 * */ class lh_splitCode { var $original_code ; var $hliteCode ; var $parsedCode ; var $endphptag='[ENDPHPTAG]'; var $re_open_tag_php = '/(?>^(.*?)<\?(??i)php)?(.*)$)/sS' ; var $re_parse_mixed_code='/(?"|\')(??:\\\\\\\\)*|.*?[^\\\\](?:\\\\\\\\)*)(\1|$))|(??:#|\/\/)(?m-s).*\r?\n)|(?:\/\*.*?(?:\*\/|$))|(?:\?>.*$)|<\?/sS'; function __lh_initialize($code) { $this->original_code = $code ; $this->hliteCode = $this->original_code ; $this->parsedCode = array() ; } function lh_splitting( $code=false ) { $this->__lh_initialize($code); if ($this->original_code==false) return false; $this->__lh_parsing_code(); for($i=1,$c=count($this->parsedCode);$i<$c;$i+=2) $this->parsedCode[$i]=str_replace('[OPENPHP]','<?',$this->parsedCode[$i]); } function lh_get_code(){ return $this->parsedCode ; } function __lh_parsing_code(){ while(preg_match($this->re_open_tag_php, $this->hliteCode, $mth)){ $this->parsedCode[] = $mth[1] ; $this->hliteCode = preg_replace_callback ( $this->re_parse_mixed_code ,array( &$this,'__lh_parsing_engine_cback' ) ,$mth[2] ); if ( strpos($this->hliteCode,$this->endphptag)!==false ) { $tmp = explode($this->endphptag, $this->hliteCode) ; $this->parsedCode[] = $tmp[0] ; $this->hliteCode = $tmp[1] ; } } if (trim($this->hliteCode)!='') $this->parsedCode[] = $this->hliteCode ; } function __lh_parsing_engine_cback($mths) { if( $mths[0]=='' ) return ''; if( $mths[0]=='<?' ) return '[OPENPHP]'; $str=($mths[0]{0}=='?')?$this->endphptag.substr($mths[0],2):$mths[0]; return $str ; } } EDIT: forgotten to say that the php tags are splitted so they are not in the results.
  14. Try this code: <?php $rex='/\[(\w+)\](?!.*?\[\\1\]).*?\[\/\\1\]/s'; while(preg_match($rex,$str,$mth)) $str=str_replace($mth[0],'',$str); ?>
  15. Mac address' are in hexadecimal rapresentation, if i'm not wrong, so you have also to consider letteral characters, something like this echo preg_replace('/\b[A-F0-9]\b/i','0$0',$mac);
×
×
  • 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.