Jump to content

Help With Testing PHP


billowingwillows

Recommended Posts

Hello all, I'm pretty new to the world of php, my journey starting when I installed Simple Machines to run a forum on a website for someone (I see this forum is also SM  :D) Anyways, I'm trying to resolve something so that emoticon code that has no space between it and the next word still displays the emoticon, because default on SMF it won't display. Here's what I mean:  :shrug:bob

 

Anyways, that's not why I came here. I came here because an admin at another website was helping me figure this one out, as I haven't been receiving any attention regarding this on SMF's support forums. We worked out to modify the $smileyPregSearch regex, and he intuitively suggested to change something specific in the code without having even seen it. It didn't work though, and he told me to "echo $smileyPregSearch and print_r($smileyPregReplacements) and let me know what the output is".

 

Now, how exactly would I do that? I think it entails writing a new document and putting in the echo code and everything, so that I can then access the document and have it display the results on screen, but I don't know how to properly associate that with all of SMF's stuff. I'm really trying to learn php through getting my hands dirty like this, and he seems much more capable of helping me than the people who haven't bothered to answer me on the support forums, but when I asked him more about how to do this, he shrugged it off 'cause he's busy and I'm a noob.  :P If I could give him those results he was asking for though, I could resolve this problem.

 

In case anyone might happen to have more input onto the specific problem, too, the code in question, as we seem to think, is this:

 

// This smiley regex makes sure it doesn't parse smileys within code tags (so [url=mailto:David@bla.com] doesn't parse the  smiley)
	$smileyPregReplacements = array();
	$searchParts = array();
	for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
	{
		$smileyCode = '<img src="' . htmlspecialchars($modSettings['smileys_url'] . '/' . $user_info['smiley_set'] . '/' . $smileysto[$i]) . '" alt="' . strtr(htmlspecialchars($smileysfrom[$i], ENT_QUOTES), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')). '" title="' . strtr(htmlspecialchars($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley" />';

		$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
		$smileyPregReplacements[htmlspecialchars($smileysfrom[$i], ENT_QUOTES)] = $smileyCode;
		$searchParts[] = preg_quote($smileysfrom[$i], '~');
		$searchParts[] = preg_quote(htmlspecialchars($smileysfrom[$i], ENT_QUOTES), '~');
	}

	$smileyPregSearch = '~(?<=[>:\?\.\s' . $non_breaking_space . '[\]()*\\\;]|^)(' . implode('|', $searchParts) . ')(?=[^[:alpha:]0-9]|$)~e' . ($context['utf8'] ? 'u' : '');

 

 

That last line on the end, he recommend removing the \s before the $non_breaking_space without ever seeing the code. Like I said, it didn't work, I showed him the code, and he asked for that output. How do I give it to him?

 

Any help, advice, input, whatever is greatly appreciated 'cause I'm struggling to get help with this! :)

 

Link to comment
Share on other sites

  • 4 weeks later...

The reason the emoticons are not parsed is because of the way SMF looks for strings to replace as img tags. It uses a PCRE Regular Expression. Basically it is like a very mini language, seemingly very simple but can be very complex. Learning regex on it's own can take weeks if not longer.

 

I would post this question in the Regular Expressions Sub-Forum of PHP Help.

 

or continue with the help of your admin friend;

 

"echo $smileyPregSearch and print_r($smileyPregReplacements) and let me know what the output is".

In PHP, debugging this way is very common for a wide range of common problems. He's telling you to echo and print_r two variables.

 

He wants to know what is in these variables at the point in code that they are used (I would assume).

To do this in PHP, all you need to do is make a new line just above where they are "used" (not updated/created), if you are this new to php this will be very difficult to grasp.

 

In this case I would put this new line below the line he told you to remove the "\s" from.

eg;

 

$smileyPregSearch = '~(?<=[>:\?\.\s' . $non_breaking_space . '[\]()*\\\;]|^)(' . implode('|', $searchParts) . ')(?=[^[:alpha:]0-9]|$)~e' . ($context['utf8'] ? 'u' : '');
echo $smileyPregSearch; print_r($smileyPregReplacements);
exit();

 

Generally you want an exit(); after your debug output, this is so it is easier to find the output in the browser. also, make sure you view the output in the "source code" of the browser page.

 

Good luck.

Link to comment
Share on other sites

Hello,

Well  I'm really trying to learn php through getting my hands dirty like this, and he seems much more capable of helping me than the people who haven't bothered to answer me on the support forums, but when I asked him more about how to do this, he shrugged it off 'cause he's busy and I'm a noob.

Link to comment
Share on other sites

To be honest I'm surprised a server admin helped you that far. I'm  guessing it's a free host, most admins just don't care/have time to help on those free hosts. (they don't get paid :P). Even if it's a paid host I would imagine they would not "support" third party scripts like SMF. Although I'm surprised SMF themselves have not given you any hints on their forums.

 

Basically, you need to learn regex.

You need to learn how regex works in PHP, the preg_match/preg_replace(_all) etc if you want to do this yourself. This can take a while to learn. But if you really want to learn PHP I would stick at it until you do it, generally, it is an easy fix.

 

Two options;

 

1. Modify the existing regex matcher.

2. Create a new (separate or inline) regex matcher to parse the smilies the original matcher missed.

 

They would generally both take as much effort, 1- having to keep the functionality of the original matcher and 2- not breaking the functionality of he original matcher.

 

Give us the output that I explained in my previous post and the whole method code (you've provided a snippet that's hard to measure) (function name(){ all code }), from the function name to the last curly brace (not the last curly brace in the file, just for that method - match them up).

 

Good luck.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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