phpbb preg_replace deprecated error - preg-replace

Hi I have recently moved to php 5.6 and am now getting some deprecated errors from a phpBB3 installation. The offending line of code is:
$tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $tpl);
Can anyone advise on how to convert this to preg_replace_callback?

I just managed to convert the expression to the new format, and I am not a php wizard, so I am a bit proud of it!
Here is what I have written to remove the error messages (bbcode.inc line 494):
$tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($m) { return (!empty($user->lang['\$m[1]'])) ? $user->lang['\$m[1]'] : ucwords(strtolower(str_replace('_', ' ', '\$m[1]'))); }, $tpl);
There is another similar line in bbcode.inc in line 370, that can be transformed in the exact same manner, but the one in line 113, I can't fix...
Obviously because the pattern comes from a variable, so it will take a little more to figure that one out.

Related

Keep getting 'Unexpected identifier' when running tests

I am trying to copy a tutorial for a Wordle solving bot but its just not going well. whenever I try to run a test on the code it doesn't work at certain points, I'll either get 'Uncaught SyntaxError: Unexpected identifier'. I'm doing this on UIlicious.
Here's what I've got so far:
I.goTo("https://www.powerlanguage.co.uk/wordle/")
I.click("reject")
I.see("Guess the Wordle")
I.click('/html/body', 40, 80)
let guessWord = null
for(Let r=0 ; r<6 ; ++r) {
guessWord = solver.suggestWord(gameState)
I.type(guessWord);
I.pressEnter()
I.wait(2)
}
let rowList = document.querySelector("game-app").shadowRoot. //
querySelector("game-theme-manager"). //
querySelector("#board").querySelectorAll("game-row");
you are probably referring to the article I wrote here : https://uilicious.com/blog/automate-wordle-via-uilicious/
This test script, is designed specifically to use uilicious.com, so you will need to edit and run it through the platform.
You can do so via the snippet here : https://snippet.uilicious.com/test/public/N5qZKraAaBsAgFuSN8wxCL
If you have syntax error there, do let me know with a snippet link - and I will try to help you respectively.
Also the snippet you provided so far, excludes the "solver" class which was initialised much further down.

Pyspark how to remove punctuation marks and make lowercase letters in Rdd?

I would like to remove punctuation mark and make the lowercase letters in RDD?
Below is my data set
l=sc.parallelize(["How are you","Hello\ then% you"\
,"I think he's fine+ COMING"])
I tried below function but I got an error message
punc='!"#$%&\'()*+,-./:;<=>?#[\\]^_`{|}~'
def lower_clean_str(x):
lowercased_str = x.lower()
clean_str = lowercased_str.translate(punc)
return clean_str
one_RDD = l.flatMap(lambda x: lower_clean_str(x).split())
one_RDD.collect()
But this gives me an error. What might be the problem? How can I fix this?
Thank you.
You are using the python translate function in a wrong way.
As I am not sure if you are using python 2.7 or python 3, I am suggesting an alternate approach.
The translate function changes a bit in python 3.
The following code will work irrespective of the python version.
def lower_clean_str(x):
punc='!"#$%&\'()*+,-./:;<=>?#[\\]^_`{|}~'
lowercased_str = x.lower()
for ch in punc:
lowercased_str = lowercased_str.replace(ch, '')
return lowercased_str
l=sc.parallelize(["How are you","Hello\ then% you","I think he's fine+ COMING"])
one_RDD = l.map(lower_clean_str)
one_RDD.collect()
Output :
['how are you', 'hello then you', 'i think hes fine coming']

how to use find count using raw method in query builder on laravel

I am trying to find count of gender using the raw statement but i get this error
Parse error: syntax error, unexpected '$total' (T_VARIABLE). Can someone please tell me whats my error
$collection='{gender:"Male"}'
$total = DB::collection('leads')->raw(function($collection)
{
return $collection->find();
});
return $total;
A semicolon is missing behind $collection='{gender:"Male"}'. (that should at least solve the error you get currently)

CoffeeScript parse error - Unexpected "(" - But there's no "(" in the code

Here's the original code:
res.write JSON.stringify {"#{result.statusCode}": "OK"}
and here's the error that both the CoffeeScript linter in SublimeText 2 and the "Try CoffeeScript" interpreter on the CoffeeScript site give me:
PARSE ERROR ON LINE 1: UNEXPECTED '('
Obviously there's no open parens in the code, so I don't understand the error. Is it a bug in the CoffeeScript parser?
The smallest line of code that does this seems to be something like this:
{"#{a}": ""}
I'm assuming that string interpolation in an object's key is valid, but I don't know for sure.
EDIT:
After some investigation it seems that it's not valid to do the string interpolation in the key because the resulting JavaScript would be invalid.
This:
{"#{a}": "stuff}
would translate to something like:
{ "" + a: "stuff"}
which isn't valid.
But can someone explain why the error message it gives me is so wrong?
I'm assuming that string interpolation in an object's key is valid, but I don't know for sure.
Unfortunately it's not.
You'll have to do something like
(json = {})[result.statusCode] = 'OK'
res.write JSON.stringify json
or if you want a one-liner
res.write (-> ((json = {})[result.statusCode] = 'OK') and JSON.stringify json)()
As for the misleading error, CoffeeScript is trying to translate your {"#{a}": ''} into {("" + a): ""} which is not valid JavaScript. CoffeeScript is throwing the error at that left paren.

preg_replace troubles

I am struggling with this regular expression.
$glossary_search[] = "/(^|>|\\s)".$glossary["glossary_name"]."($|<|\\s)/i";
$glossary_replace[] = "\$1<a href='/jargon-buster/".tapestry_hyphenate($glossary["glossary_name"]).".html' title='".$glossary["glossary_name"]."' target='_blank'>".$glossary["glossary_name"]."</a>\$2";
return preg_replace($glossary_search,$glossary_replace,$text);
I am trying to replace words in a product description with a hyperlink. The code above works if the word has a space either side but does not work if it has a full stop, comma or "<". Can anyone spot my mistake?
Thanks,
Simon
I think you might need to use preg_quote and htmlentities?
$glossary_search[] = "/(^|>|\\s)".preg_quote(htmlentities($glossary["glossary_name"],ENT_COMPAT,'UTF8'))."($|<|\\s)/i";
$glossary_replace[] = "\$1<a href='/jargon-buster/".tapestry_hyphenate($glossary["glossary_name"]).".html' title='".$glossary["glossary_name"]."' target='_blank'>".$glossary["glossary_name"]."</a>\$2";
return preg_replace($glossary_search,$glossary_replace,$text);