too long

I have data from SQL database that contains xml text which are being echoed with php script

For example this:
No:1|TestName:MachineAlfonso|TestParameter:< asdf/>|TestConnection:1234;

This data is later being parsed to Unity for later uses.
however when i try to print it in unity, It somehow converting the < to &lt ; and the > to &gt ;

The full output become
No:1|TestName:MachineAlfonso|TestParameter:&lt ; asdf/&gt ;|TestConnection:1234;

Is there any function to print the output to become a human readable sign not as html code? because those two signs( < and >) are just some than many other html simple that i want to convert.

this is the C# script i use to print the echoed data

   public IEnumerator RefreshData()
   {
        //load the data
        //dataLoader is the link of the echoed php data
        WWW InventoryDatabase = new WWW(dataLoaderURL);

        //wait until its done dowloading
        yield return InventoryDatabase;

        string abc = InventoryDatabase.text;
        Debug.Log("text is: " + abc);
   }
dongsheng6056
dongsheng6056 使用System.Net.WebUtility.HtmlEncode(string)或System.Net.WebUtility.HtmlDecode(string)
一年多之前 回复
doucheng8471
doucheng8471 我不知道是否有任何特定于HTML的方法,但也许它足以让你使用string.Replace或Regex.Replace?
一年多之前 回复

2个回答

In the end, in order not to waste time, I just use replace like @derHugo has suggested.
Hopefully there are better and cleaner ways to do it. But hey, its a start. ^_^

Here is the code snippets if someone has similar problem:

     public IEnumerator RefreshData()
       {
            //load the data
            //dataLoader is the link of the echoed php data
            WWW InventoryDatabase = new WWW(dataLoaderURL);

            //wait until its done dowloading
            yield return InventoryDatabase;

             string temp = InventoryDatabase.text;
                    temp = temp.Replace("&lt;", "asdf");
                    temp = temp.Replace("&gt;", "<");
                    temp = temp.Replace("&amp;", "&");
                    temp = temp.Replace("&quot;", "\"");

            //this "Inventory" contains all the data from the echoed file
            string Inventory =  temp;

            string abc = InventoryDatabase.text;
            Debug.Log("text is: " + Inventory);
       }
dongqu2863
dongqu2863 工作得很好。 谢谢
大约一年之前 回复



尝试PHP的 htmlentities()</ code>函数。 它是专门为此目的而设计的:</ p>

查看更多: http://php.net/manual/en/function.htmlentities.php </ p>
</ div>

展开原文

原文

Try PHP's htmlentities() function. It's designed specifically for this purpose:

See more: http://php.net/manual/en/function.htmlentities.php

duanqiao1961
duanqiao1961 htmlentities()仅在您将值输出为HTML时使用。 如果输出其他格式,请不要使用它。
一年多之前 回复
dstjh46606
dstjh46606 是的....,我在我的PHP脚本中使用htmlentities()。 回声输出也很好(它显示<>)..但是当我将这个回声数据解析为1时,它会恢复为(&lt;和&gt;)
一年多之前 回复
dtf24224
dtf24224 我怀疑OP得到的输出已经是这样的结果了,他正在Unity中寻找一些东西来恢复它。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐