Jump to content

rarebit

Members
  • Posts

    1,002
  • Joined

  • Last visited

Posts posted by rarebit

  1. I likes it, a lot!

    Never used 'back references' before (ref), very useful.

    As expected the following fails a little...

    $string = "I saw 'em 'ther day like 'had bells' on they did \"that arh\" y'know! But 'hey what's thee' expect like?";
    print $string."<br>";
    preg_match_all('/\B(["\'])(.+?)\1\B/s', $string, $matches);
    print_r($matches[0]);
    

     

    VERY GOOD, CHEERS MR dARKwATER!

  2. Hi,

    Whats the best way to extract quoted strings?

    Given the following example:

    this isn't an "interesting example", but 'then what' would we expect?

    The main problem is the single quote in "isn't", can this be (generally) caught because in this type of situation it is concatenated between other characters, whereas a string generally has whitespace on at least one side. This however wouldn't catch situations like:

    I saw 'em 'ther day like...

    Any suggestions?

    Cheers

  3. Basically continuing from this thread, i'm wondering if theres a way to ignore the stopword list without recompiling.

     

    Is it that the fields are stored with something like dictionary compression (ie where stopwords appear), thus less for the search.

     

    Cheers

  4. OK, me struggles, even though syntax seems right....

    I changed the table creation like this:

    $s = "CREATE TABLE test_search (id int not null primary key auto_increment, title varchar(128), info text, FULLTEXT (title,info) ) ENGINE=MyISAM DEFAULT CHARSET=latin1";
    

    and revised my search like this:

    $s = "SELECT *, MATCH(title,info) AGAINST ('to') AS score FROM test_search";
    $res = mysql_query($s, $conn) or die(mysql_error());
    while ($a = mysql_fetch_array($res))
    {
    print $a['id'].": ".$a['title'].": ".$a['score']."<br>";
    }
    

    but alas, no results, until out of general interest and reading around I covered stop words, which gave me a thought, so:

    $s = "SELECT *, MATCH(title,info) AGAINST ('borrower question') AS score FROM test_search WHERE MATCH(title,info) AGAINST ('borrower question')";
    

  5. Yes, i've tried various combinations using COUNT, but i'm wanting to count the occurrences per result, without having to return all the data (because later i'll want to ORDER BY it, then LIMIT).

     

    Do you see the distinction, i'm not wanting to count how many results, but the actual number of occurrences per data block (result).

  6. What follows is a little example setup to test with.

    I'm wanting to be able to count how many matches there are in each hit. So in the example search there should be 2 hits in the first, 1 in the second and 1 in the third. How am I supposed to do this?

     

    $host = 'localhost';
    $user = 'user';
    $pass = 'pass';
    $db = 'db';
    $conn = mysql_connect($host, $user, $pass) or die(mysql_error());
    mysql_select_db($db, $conn) or die(mysql_error());
    
    $s = "DROP TABLE test_search";
    mysql_query($s, $conn);
    
    $s = "CREATE TABLE test_search (id int not null primary key auto_increment, title varchar(128), info text )";
    if(mysql_query($s, $conn))
    {
    print "Created table<br>";
    $s = "INSERT INTO test_search VALUES 
    	('', 'Hamlet (Act III, Scene I)', 'To be, or not to be: that is the question'), 
    	('', 'Hamlet (Act I, Scene III)', 'Neither a borrower nor a lender be; For loan oft loses both itself and friend, and borrowing dulls the edge of husbandry'), 
    	('', 'Hamlet (Act I, Scene III)', 'This above all: to thine own self be true'), 
    	('', 'Julius Caesar (Act III, Scene II)', 'Friends, Romans, countrymen, lend me your ears; I come to bury Caesar, not to praise him')
    	";
    $res = mysql_query($s, $conn) or die(mysql_error());
    }
    else
    {
    print "Table creation failed<br>";
    }
    
    print "<br><br>";
    print "<h2>Search: 1</h2>";
    
    $s = "SELECT * FROM test_search WHERE info LIKE '%be%' ";
    $res = mysql_query($s, $conn) or die(mysql_error());
    
    while ($a = mysql_fetch_array($res))
    {
    print $a['id'].": ".$a['title']."<br>";
    }
    
    print "<br><br><h2>DUMP</h2>";
    
    $s = "SELECT * FROM test_search";
    $res = mysql_query($s, $conn) or die(mysql_error());
    while ($a = mysql_fetch_array($res))
    {
    print "<b>".$a['title']."</b><br>".$a['info']."<br><hr><br>";
    }
    

  7. OK, OK, I was being silly!

    It turns out that I was doing some pre-parsing of < > elements to disable script inclusions, so i've added another parsed variation to the list:

    "/>:O/is",
    

    Solves for both JS and PHP!

     

    Cheers...

  8. The thing is, it works ok in the tests, but this doesn't do it either?

    '/'.preg_quote('>', '/').'/is',
    

     

    and i've just noticed that some of the original code was truncated... so to show I am smiling on the inside...

    $pattern = array(
    				'/\[b\](.+?)\[\/b\]/is',
    				'/\[i\](.+?)\[\/i\]/is',
    				'/\[u\](.+?)\[\/u\]/is',
    				'/\[h1\](.+?)\[\/h1\]/is',
    				'/\[h2\](.+?)\[\/h2\]/is',
    				'/\[h3\](.+?)\[\/h3\]/is',
    				'/\[h4\](.+?)\[\/h4\]/is',
    				'/\[sub\](.+?)\[\/sub\]/is',
    				'/\[sup\](.+?)\[\/sup\]/is',
    				'/\[tt\](.+?)\[\/tt\]/is',
    				'/\[s\](.+?)\[\/s\]/is',					
    				'/\[em\](.+?)\[\/em\]/is',
    				'/\[strong\](.+?)\[\/strong\]/is',
    				'/\[samp\](.+?)\[\/samp\]/is',
    				'/\[kbd\](.+?)\[\/kbd\]/is',
    				'/\[code\](.+?)\[\/code\]/is',
    				******************************************
    				'/\[quote=(.+?)\](.+?)\[\/quote\]/is',
    				'/\[quote\](.+?)\[\/quote\]/is',
    				'/\[size=(.+?)\](.+?)\[\/size\]/is',
    				'/\[color=(.+?)\](.+?)\[\/color\]/is', 
    				'/\[url\]((www|ftp|)\.[^ \\\"\\n\\r\\t<]*?)\[\/url\]/is',
    				'/\[url=([\w]+?:\/\/[^ \\\"\\n\\r\\t<]*?)\](.*?)\[\/url\]/is',
    				'/\[url=((www|ftp)+?\.[^ \\\"\\n\\r\\t<]*?)\](.*?)\[\/url\]/is',
    				'/\[url\]([\w]+?:\/\/[^ \\\"\\n\\r\\t<].*?)\[\/url\]/is', 
    				'/\[img\]((www)\.[^ \\\"\\n\\r\\t<]*?)\[\/img\]/is',
    				'/\[img\]([\w]+?:\/\/[^ \\\"\\n\\r\\t<].*?)\[\/img\]/is',
    				'/\[img\]((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/[^ \\\"\\n\\r\\t<]*?)\[\/img\]/is',
    				'/\[email\]([\w]+?@(([\w]+)([\w]+))\.(([\w]+)([\w]+)).*?)\[\/email\]/is', 
    				'/\[email=((([\w]+)@(([\w]+)([\w]+))\.(([\w]+)([\w]+))).*?)\](.+?)\[\/email\]/is',
    				'/:-\)/is',
    				'/:-D/is',
    				'/;-D/is',
    				'/;-\)/is',
    				'/:-\*/is',
    				'/S-\)/is',
    				'/8-D/is',
    				'/\?\?\?/is',
    				'/:-P/is',
    				'/:-O/is',
    				"/>:O/is",
    				'/:-\[/is',
    				'/:-\(/is',
    				'/:\*\(/is',
    				'/:-X/is',
    				'/:-\//is'
    				);
    //'/'.preg_quote('>', '/').'/is',
    $replacement = array(
    					'<b>$1</b>',
    					'<i>$1</i>',
    					'<u>$1</u>',
    					'<h1>$1</h1>',
    					'<h2>$1</h2>',
    					'<h3>$1</h3>',
    					'<h4>$1</h4>',
    					'<sub>$1</sub>',
    					'<sup>$1</sup>',
    					'<tt>$1</tt>',
    					'<s>$1</s>',
    					'<em>$1</em>',
    					'<strong>$1</strong>',
    					'<samp>$1</samp>',
    					'<kbd>$1</kbd>',
    					"<table width='100%' cellpadding='5' bgcolor='".$theme_wysiwyg['bgcode']."'><tr><td><pre class='codex'><code class='codex'>$1</code></pre></td></tr></table>",
    					"<table width='100%' cellpadding='5' bgcolor='".$theme_wysiwyg['bgcode']."'><tr><td><b>$1</b><hr noshade></td></tr><tr><td><pre class='codex'><code class='codex'>$2</code></pre></td></tr></table>",
    					"<table width='100%' cellpadding='5' class='quotex'><tr><td><b>$1</b><hr noshade></td></tr><tr><td><q class='quotex'>$2</q></td></tr></table>",
    					"<table width='100%' cellpadding='5' class='quotex'><tr><td><q>$1</q class='quotex'></td></tr></table>",
    					"<span style='font-size:$1'>$2</span>",
    					"<span style='color:$1'>$2</span>", 
    					"<a href='http://$1' target='blank'>$1</a>",
    					"<a href='$1' target='blank'>$2</a>",
    					"<a href='http://$1' target='blank'>$3</a>",
    					"<a href='$1' target='blank'>$1</a>", 
    					"<img src='$1' alt='$1'>",
    					"<img src='$1' alt='$1'>", 
    					"<img src='http://$1' alt='http://$1'>", 
    					"<a href='mailto:$1'>$1</a>",
    					"<a href='mailto:$1'>$10</a>", 
    					"<img src='".$base."smiley.gif'>",
    					"<img src='".$base."grin.gif'>",
    					"<img src='".$base."cheesy.gif'>",
    					"<img src='".$base."wink.gif'>",
    					"<img src='".$base."kiss.gif'>",
    					"<img src='".$base."rolleyes.gif'>",
    					"<img src='".$base."cool.gif'>",
    					"<img src='".$base."huh.gif'>",
    					"<img src='".$base."tongue.gif'>",
    					"<img src='".$base."shocked.gif'>",
    					"<img src='".$base."angry.gif'>",
    					"<img src='".$base."embarrassed.gif'>",
    					"<img src='".$base."sad.gif'>",
    					"<img src='".$base."cry.gif'>",
    					"<img src='".$base."lipsrsealed.gif'>",
    					"<img src='".$base."undecided.gif'>"
    					);
    $s = preg_replace($pattern, $replacement, $s);
    

    The starry line is just another variation on code blocks, but it rally did get in the way here so it ended up right out of the way...

     

     

    I've also got this issue on the exact same string when using JS...

     

    me eh poco loco eh a losta!

  9. Boo Hoo!

     

    mmm, that's how I have it in the production code, hadn't noticed here, but for some reason it works in the test but not the production:

    search = new Array(
    	/\[b\](.*?)\[\/b\]/ig,
    	/\[i\](.*?)\[\/i\]/ig,
    	/\[u\](.*?)\[\/u\]/ig,
    	/\[h1\](.*?)\[\/h1\]/ig,
    	/\[h2\](.*?)\[\/h2\]/ig,
    	/\[h3\](.*?)\[\/h3\]/ig,
    	/\[h4\](.*?)\[\/h4\]/ig,
    	/\[sub\](.*?)\[\/sub\]/ig,
    	/\[sup\](.*?)\[\/sup\]/ig,
    	/\[tt\](.*?)\[\/tt\]/ig,
    	/\[s\](.*?)\[\/s\]/ig,
    	/\[em\](.*?)\[\/em\]/ig,
    	/\[strong\](.*?)\[\/strong\]/ig,
    	/\[samp\](.*?)\[\/samp\]/ig,
    	/\[kbd\](.*?)\[\/kbd\]/ig,
    	/\[code\](.*?)\[\/code\]/ig,
    	/\[code=(.*?)\]

     

    All the escapism is because it's dumped out by php, and i've tried extra escaping on the backslash...

     

    Cheers

  10. Hi,

    I've got basically the same problem in JS as well, but the php version works in tests but not in production!

    Heres the test:

    <?php
    $s = "Hello Mr. >!";
    $pattern = array('/\076:O/is', '/\x3e:O/is', '/\>:O/is');
    $replacement = array('XYZ','xyz', 'abc');
    $s = preg_replace($pattern, $replacement, $s);
    print $s;
    ?>
    

     

    and this is the other:

    $pattern = array(
    				'/\[b\](.+?)\[\/b\]/is',
    				'/\[i\](.+?)\[\/i\]/is',
    				'/\[u\](.+?)\[\/u\]/is',
    				'/\[h1\](.+?)\[\/h1\]/is',
    				'/\[h2\](.+?)\[\/h2\]/is',
    				'/\[h3\](.+?)\[\/h3\]/is',
    				'/\[h4\](.+?)\[\/h4\]/is',
    				'/\[sub\](.+?)\[\/sub\]/is',
    				'/\[sup\](.+?)\[\/sup\]/is',
    				'/\[tt\](.+?)\[\/tt\]/is',
    				'/\[s\](.+?)\[\/s\]/is',					
    				'/\[em\](.+?)\[\/em\]/is',
    				'/\[strong\](.+?)\[\/strong\]/is',
    				'/\[samp\](.+?)\[\/samp\]/is',
    				'/\[kbd\](.+?)\[\/kbd\]/is',
    				'/\[code\](.+?)\[\/code\]/is',
    				'/\[code=(.+?)\]

     

    Can you see why it's malfunctioning, or is it just the curse of the angry emoticon!

  11. Hi i'm stuck on how to make this one work?

    <script type='text/javascript'>
    var search = new Array(/\076:O/ig, /\x3e:O/ig, /\>:O/ig);
    var replace = new Array('XYZ','xyz', 'abc');
    var s = "Hello Mr. >!";
    s.replace(search[0],replace[0]);
    s.replace(search[1],replace[1]);
    s.replace(search[2],replace[2]);
    document.write(s);
    </script>
    

  12. What's the best way to implement a site capable of changing languages?

     

    1. Include appropriate page, filled with 'define''s.

    2. Include an appropriate page with an array and use a function to extract.

    3. Use a function to extract from a database.

    4. Other suggestions?

     

    ?

  13. How do you parse a definitely html page using SimpleXML, I keep getting errors...

     

    $fn = "../test_pages/lq/index.html";
    $s = file_get_contents($fn);
    
    $dom = null;
    try {
    $dom = @new SimpleXMLElement($s);
    } catch (Exception $e) {
    echo "error";
    }
    print_r($dom);
    

  14. Basically into some form of array so it can be studied for seo quality...

     

    DOMDocument, Tidy and a few others don't seem to be installed on my server, so i'm currently having a look at XML Parser and simpleXML, but have also grabbed a few preg_split concoctions.

     

    Any suggestions?

  15. Ok, i'm struggling with preg_split (and PREG_SPLIT_DELIM_CAPTURE), but surely theres got to be an easier way than this?

    ob_start();
    $x = eval("phpinfo();");
    $l = ob_get_contents();
    ob_end_clean();
    
    $chars = preg_split('/Client API version <\/td><td class="v">(*) <\/td>/', $l, -1, PREG_SPLIT_DELIM_CAPTURE);
    

     

    Is there a way to get 'phpinfo' back as an array?

  16. phpinfo returns the mysql client version. Not the actual version of the MySQL server. To get the version of MySQL installed first connect to MySQL then use the mysql_get_server_info function.

     

    This does give what I want, but at the stage of use I wouldn't have any DB details.

     

    This is now the best i've found, but still no version (unless I search the system myself?):

    if (extension_loaded('mysql'))
    {
    print "MySQL available<br>";
    }
    

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