unicode where to use it

this is related to vbulletin. But some how it is a general PHP question. I have what we can call (addon for vbulletin board) which has no support for my problem. And my question is simple (i think). it just, How to return  the variable: (source_name) that you can see in the attached code as a UNICODE variable?

am asking that because the variable source_name returns for example: "A   instead of: "A
so, i thing if i'll return it as unicode it might help to get the real value. And I found this: convert_urlencoded_unicode()
if it will help; so where do i use it in the attached code?

*my understanding and suggestion to the problem, both might me wrong.
<?php
/**
 * Moderation Auto-PM
 * Automaticly sends a PM when a thread, post or attachment is moderated
 */
 
/**
 * Parses the message phrase replacing the {placeholder}s
 * 
 * @package 	mod_autopm
 * @version 	2.0.1
 * @author 		Alan Wagstaff
 * @copyright 	(C) 2006 Alan Wagstaff
 */
 
class autopm_parser
{
 
	/**
	 * An array of valid placeholders to parse
	 * 
	 * @var 	array
	 */
	var $placeholders = array('{user_id}',
							  '{user_name}',
							  '{moderator_id}',
							  '{moderator_name}',
							  '{item_id}',
							  '{item_name}',
							  '{source_id}',
							  '{source_name}',
							  '{dest_id}',
							  '{dest_name}',
							  '{reason}',
							  '{homepage_url}',
							  '{forum_url}',
							  '{old_title}'
							  );
 
	/**
	 * The original phrase text
	 * 
	 * @var 	char
	 */
	var $phrasetext = '';
 
	/**
	 * The parsed phrase text
	 * 
	 * @var 	char
	 */
	var $phrasetext_parsed = '';
 
	/**
	 * The array of text that will be parsed in to the phrase
	 * 
	 * @var 	array
	 */
	var $items = array();
 
	/**
	 * The item ID
	 * 
	 * @var 	int
	 */
	var $item_id = 0;
 
	/**
	 * The type of item (thread, post or attachment)
	 * 
	 * @var		char
	 */
	var $item_type = '';
 
	/**
	 * The action being performed
	 * 
	 * @var 	char
	 */
	var $action = '';
 
	/**
	 * Source ID (for thread or post moves)
	 * 
	 * @var 	int
	 */
	var $source = 0;
 
	/**
	 * Destination ID (for thread or post moves)
	 * 
	 * @var 	int
	 */
	var $dest = 0;
 
	/**
	 * Reason (for deletions)
	 * 
	 * @var 	char
	 */
	var $reason = '';
 
	/**
	 * Any extra text (new thread title, etc)
	 * 
	 * @var 	char
	 */
	var $extra = '';
 
	/**
	 * Can user view the source forum?
	 * 
	 * @var 	bool
	 */
	var $view_source = true;
 
	/**
	 * Can user view the destination forum?
	 * 
	 * @var 	bool
	 */
	var $view_dest = true;
 
	/**
	 * Recipients username
	 * 
	 * @var 	char
	 */
	var $recipient = '';
 
	/**
	 * A reference to the vBulletin object
	 * 
	 * @var 	object
	 */
	var $vbulletin = null;
 
	/**
	 * Constructor - sets up the vBulletin object
	 *
	 * @param 	object	The vBulletin object
	 *
	 * @return 	void
	 */
	function autopm_parser(&$vbobj)
	{
 
		$this->vbulletin =& $vbobj;
 
	}
 
	/**
	 * Parses the phrase
	 * 
	 * @return 		bool
	 */
	function parse_phrase()
	{
 
		if (strlen($this->phrasetext) < 1)
		{
			// No phrase text
			return false;
		}
 
		if (count($this->items) < 1)
		{
			// No args, just throw back the unparsed phrase then give up
			$this->phrasetext_parsed = $this->phrasetext;
 
			return true;
		}
 
		foreach ($this->items AS $id => $text)
		{
			// Loop through the args replacing each one we find in the phrase text
			if (in_array($id, $this->placeholders))
			{
				$this->phrasetext = str_replace($id, $text, $this->phrasetext);
			}
		}
 
		// Set the parsed text
		$this->phrasetext_parsed = $this->phrasetext;
 
		return true;
 
	}
 
	/**
	 * Fetches the vars for this->items
	 * 
	 * @return 		bool
	 */
	function fetch_items()
	{
 
		// 1. Fetch the item info depending on this->type
		switch ($this->item_type)
		{
 
			case 'thread':
				{
 
					$item_info_a = $this->vbulletin->db->query_first("SELECT title AS item_name, postuserid AS user_id, postusername AS user_name, dateline
						FROM " . TABLE_PREFIX . "thread
						WHERE threadid = " . $this->vbulletin->input->clean($this->item_id, TYPE_UINT));
 
					break;
 
				}
 
			case 'post':
			case 'attachment':
				{
 
					$item_info_a = $this->vbulletin->db->query_first("SELECT SUBSTRING(post.pagetext, 1, 60) AS item_name, post.userid AS user_id, post.username AS user_name,
							thread.threadid AS source_id, thread.title AS source_name, post.dateline AS dateline
						FROM " . TABLE_PREFIX . "post AS post
						LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON (post.threadid = thread.threadid)
						WHERE postid=" . $this->vbulletin->input->clean($this->item_id, TYPE_UINT));
 
					break;
 
				}
 
		}
 
		// 2.  Check the user can view the source/dest forums, if so, get the forum names
		if ($this->item_type == 'thread')
		{
 
			$this->canview($item_info_a['user_id'], $this->source, $this->dest);
 
			// Source
			if ($this->view_source)
			{
				$source_name_a = $this->vbulletin->db->query_first("SELECT title_clean FROM " . TABLE_PREFIX . "forum WHERE forumid=" . $this->vbulletin->input->clean($this->source, TYPE_UINT));
			}
 
			// Destination
			if ($this->view_dest)
			{
				$dest_name_a = $this->vbulletin->db->query_first("SELECT title_clean FROM " . TABLE_PREFIX . "forum WHERE forumid=" . $this->vbulletin->input->clean($this->dest, TYPE_UINT));
			}
 
		}
 
		if ($this->item_type == 'post' AND $this->dest)
		{
			// Fetch the destination thread details for the post move
			$dest_name_a = $this->vbulletin->db->query_first("SELECT title AS title_clean FROM " . TABLE_PREFIX . "thread WHERE threadid=" . $this->vbulletin->input->clean($this->dest, TYPE_UINT));
		}
 
		if ($this->item_type == 'thread' AND $this->action == 'edit_title')
		{
			// Stuff new title in item_name and put the old title in title_old
			$title_old = $item_info_a['item_name'];
			$item_info_a['item_name'] = $this->extra;
		}
 
		// Check the age cutoff
		if ($this->vbulletin->options['cit_autopm_agecutoff'])
		{
			$cutoff = TIMENOW - $this->vbulletin->options['cit_autopm_agecutoff'] * 86400;
 
			if ($item_info_a['dateline'] < $cutoff)
			{
				return false;
			}
		}
 
		// Un-htmlspecialchars_uni
		$item_info_a['item_name'] = str_replace('&lt;', '<', $item_info_a['item_name']);
		$item_info_a['item_name'] = str_replace('&gt;', '>', $item_info_a['item_name']);
		$item_info_a['item_name'] = str_replace('&quot;', '"', $item_info_a['item_name']);
 
		// 3.  Fill in the blanks
		$this->set_items(array(
			'{user_id}'			=> $item_info_a['user_id'],
			'{user_name}'		=> $item_info_a['user_name'],
			'{moderator_id}'	=> $this->vbulletin->userinfo['userid'],
			'{moderator_name}'	=> $this->vbulletin->userinfo['username'],
			'{item_id}'			=> $this->item_id,
			'{item_name}'		=> $item_info_a['item_name'] . ($this->item_type == 'post' ? '...' : ''),
			'{source_id}'		=> ($this->item_type == 'thread' ? $this->source : $item_info_a['source_id']),
			'{source_name}'		=> ($this->item_type == 'thread' ? $source_name_a['title_clean'] : $item_info_a['source_name']),
			'{dest_id}'			=> $this->dest,
			'{dest_name}'		=> $dest_name_a['title_clean'],
			'{reason}'			=> $this->reason,
			'{homepage_url}'	=> $this->vbulletin->options['homeurl'],
			'{forum_url}'		=> $this->vbulletin->options['bburl'],
			'{old_title}'		=> $title_old,
			));
 
		// 4. Set the recipients for later use
		$this->recipient = $item_info_a['user_name'];
 
		return true;
 
	}
 
	/**
	 * Checks to see if the user has access to view the source/dest forum
	 * 
	 * @param 		int			The user ID to check
	 * @param 		int			The ID of the source forum
	 * @param 		int			The ID of the dest forum
	 * 
	 * @return 		void
	 */
	function canview($userid = 0, $source = 0, $dest = 0)
	{
 
		$userinfo = fetch_userinfo($userid);
		cache_permissions($userinfo);
 
		$this->view_source = ($userinfo['forumpermissions']["$source"] & $this->vbulletin->bf_ugp_forumpermissions['canview']);
		$this->view_dest = ($userinfo['forumpermissions']["$dest"] & $this->vbulletin->bf_ugp_forumpermissions['canview']);
 
	}
 
	/**
	 * Checks for a recycle bin forum
	 * 
	 * @return 		void
	 */
	function check_recycle_bin()
	{
 
		if (($this->dest == $this->vbulletin->options['cit_autopm_recyclebin']) AND ($this->item_type == 'thread') AND ($this->action == 'move'))
		{
			$this->action = 'delete';
		}
 
	}
 
	/**
	 * Cleans this->items and puts them in the array
	 * 
	 * @param 		array		An array of items to be parsed-in
	 * 
	 * @return 		bool
	 */
	function set_items($items_a)
	{
 
		// Check we've got something to do
		if ((!is_array($items_a)) OR (count($items_a) < 1))
		{
			return false;
		}
 
		// Clean the array and put it in this->items
		$this->items = $this->vbulletin->input->clean($items_a, TYPE_ARRAY_STR);
 
		return true;
 
	}
 
	/**
	 * Returns the parsed phrase text
	 * 
	 * @return 		char
	 */
	function get_phrasetext_parsed()
	{
 
		return $this->vbulletin->input->clean($this->phrasetext_parsed, TYPE_STR);
 
	}
 
}
 
?>

Open in new window

LVL 3
sniper038Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
you should be able to wrap it inside unicode_encode(), or is this not what you mean?

-r-
sniper038Author Commented:
yeah that's sure, but where exactly?
I tried to put source_name inside unicode_encode(*) wherever it existed in the code. and i had no idea what i was doing :D and non worked with me!
because i don't know much about PHP
LordOfPortsCommented:
The issue you described &quot;A instead of "A is not related to Unicode, special HTML characters have been escaped most likely using the htmlentities function http://www.php.net/htmlentities e.g.:

$sText = '"A';

echo htmlentities($sText); // outputs: &quot;A

to reverse the change you can use the html_entity_decode function http://www.php.net/manual/en/function.html-entity-decode.php e.g.

echo html_entity_decode($sText); // outputs: "A
sniper038Author Commented:
i tried to use> htmlentities but it returned all codes of source_name characters where source_code includes non english characters.
however, that helped me notice the following in the attached code:
// Un-htmlspecialchars_uni
            $item_info_a['item_name'] = str_replace('&lt;', '<', $item_info_a['item_name']);
            $item_info_a['item_name'] = str_replace('&gt;', '>', $item_info_a['item_name']);
            $item_info_a['item_name'] = str_replace('&quot;', '"', $item_info_a['item_name']);

 where I added:
            $source_name_a['title_clean'] = str_replace('&quot;', '"', $source_name_a['title_clean']);

and that works perfectly

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.