當前位置:編程學習大全網 - 源碼下載 - php 分詞,搜索引擎,技術

php 分詞,搜索引擎,技術

妳好,很高興為妳解答:

如果妳僅僅是要把長句中的單詞分出來,那是很簡單的:

<?php

$str?=?"Google?Translate?for?Business!";

$str?=?preg_replace("{\.|\,|\;|\:|\'|\"|\?|\!|\<|\>|\(|\)}",?"",?$str);?//?移除所有標點符號

$arr?=?array_unique(explode("?",?$str));?//?以空格分割,並去重

var_dump($arr);

>

以下是壹段測試文本:

Instead?of?lots?of?commands?to?output?HTML?(as?seen?in?C?or?Perl),?PHP?pages?contain?HTML?with?embedded?code?that?does?"something"?(in?this?case,?output?"Hi,?I'm?a?PHP?script!").?The?PHP?code?is?enclosed?in?special?start?and?end?processing?instructions?<?php?and?>?that?allow?you?to?jump?into?and?out?of?"PHP?mode."

What?distinguishes?PHP?from?something?like?client-side?JavaScript?is?that?the?code?is?executed?on?the?server,?generating?HTML?which?is?then?sent?to?the?client.?The?client?would?receive?the?results?of?running?that?script,?but?would?not?know?what?the?underlying?code?was.?You?can?even?configure?your?web?server?to?process?all?your?HTML?files?with?PHP,?and?then?there's?really?no?way?that?users?can?tell?what?you?have?up?your?sleeve.

The?best?things?in?using?PHP?are?that?it?is?extremely?simple?for?a?newcomer,?but?offers?many?advanced?features?for?a?professional?programmer.?Don't?be?afraid?reading?the?long?list?of?PHP's?features.?You?can?jump?in,?in?a?short?time,?and?start?writing?simple?scripts?in?a?few?hours.

Although?PHP's?development?is?focused?on?server-side?scripting,?you?can?do?much?more?with?it.?Read?on,?and?see?more?in?the?What?can?PHP?do?section,?or?go?right?to?the?introductory?tutorial?if?you?are?only?interested?in?web?programming.

輸出結果:

Instead,?of,?lots,?commands,?to,?output,?HTML,?as,?seen,?in,?C,?or,?Perl,?PHP,?pages,?contain,?with,?embedded,?code,?that,?does,?something,?this,?case,?Hi,?Im,?a,?script,?The,?is,?enclosed,?special,?start,?and,?end,?processing,?instructions,?php,?,?allow,?you,?jump,?into,?out,?mode?What,?distinguishes,?from,?like,?client-side,?JavaScript,?the,?executed,?on,?server,?generating,?which,?then,?sent,?client,?would,?receive,?results,?running,?but,?not,?know,?what,?underlying,?was,?You,?can,?even,?configure,?your,?web,?process,?all,?files,?theres,?really,?no,?way,?users,?tell,?have,?up,?sleeve?The,?best,?things,?using,?are,?it,?extremely,?simple,?for,?newcomer,?offers,?many,?advanced,?features,?professional,?programmer,?Dont,?be,?afraid,?reading,?long,?list,?PHPs,?short,?time,?writing,?scripts,?few,?hours?Although,?development,?focused,?server-side,?scripting,?do,?much,?more,?Read,?see,?What,?section,?go,?right,?introductory,?tutorial,?if,?only,?interested,?programming

使用sort()對其進行排序:

C,?Dont,?HTML,?Hi,?Im,?Instead,?JavaScript,?PHP,?PHPs,?Perl,?Read,?The,?What,?You,?a,?advanced,?afraid,?all,?allow,?and,?are,?as,?be,?best,?but,?can,?case,?client,?client-side,?code,?commands,?configure,?contain,?development,?distinguishes,?do,?does,?embedded,?enclosed,?end,?even,?executed,?extremely,?features,?few,?files,?focused,?for,?from,?generating,?go,?have,?hours?Although,?if,?in,?instructions,?interested,?into,?introductory,?is,?it,?jump,?know,?like,?list,?long,?lots,?many,?mode?What,?more,?much,?newcomer,?no,?not,?of,?offers,?on,?only,?or,?out,?output,?pages,?php,?process,?processing,?professional,?programmer,?programming,?reading,?really,?receive,?results,?right,?running,?script,?scripting,?scripts,?section,?see,?seen,?sent,?server,?server-side,?short,?simple,?sleeve?The,?something,?special,?start,?tell,?that,?the,?then,?theres,?things,?this,?time,?to,?tutorial,?underlying,?up,?users,?using,?was,?way,?web,?what,?which,?with,?would,?writing,?you,?your

-----------------------------------

如有疑問歡迎追問!

滿意請點擊右上方選為滿意回答按鈕麽麽噠 o(∩_∩)o

  • 上一篇:做壹個web登錄界面,login.jsp裏面進行登錄,loginservlet進行登錄處理,然後轉回login.jsp進行顯示
  • 下一篇:跪求C4.5算法,C語言的……
  • copyright 2024編程學習大全網