更確切地說,我需要能夠地帶HTML標籤一樣好這個腳本的作用:zubrag.com/tools/html-tags-stripper.php轉換HTML頁面,以純文本使用PHP
我需要能夠做到這一點在我的本地(XAMPP服務器)與任何URL,但現在我想用這個網址從剝離標籤,因爲這是凌亂它可以得到:http://static.anaf.ro/static/10/Timis/Timis.htm
我有,不起作用,我不知道爲什麼或如何解決它。 這裏的是代碼來自:nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page
我已經添加了此行的代碼,但它仍然無法工作......
$text = file_get_contents('http://static.anaf.ro/static/10/Timis/Timis.htm');
下面是原始代碼(請注意,原代碼沒有行從上面被我添加的那行)
/**
* Copyright (c) 2008, David R. Nadeau, NadeauSoftware.com.
* All rights reserved.
* See:
* http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page
*/
$text = file_get_contents('http://static.anaf.ro/static/10/Timis/Timis.htm');
function strip_html_tags($text)
{
// PHP's strip_tags() function will remove tags, but it
// doesn't remove scripts, styles, and other unwanted
// invisible text between tags. Also, as a prelude to
// tokenizing the text, we need to insure that when
// block-level tags (such as <p> or <div>) are removed,
// neighboring words aren't joined.
$text = preg_replace(
array(
// Remove invisible content
'@<head[^>]*?>.*?</head>@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
'@<object[^>]*?.*?</object>@siu',
'@<embed[^>]*?.*?</embed>@siu',
'@<applet[^>]*?.*?</applet>@siu',
'@<noframes[^>]*?.*?</noframes>@siu',
'@<noscript[^>]*?.*?</noscript>@siu',
'@<noembed[^>]*?.*?</noembed>@siu',
// Add line breaks before & after blocks
'@<((br)|(hr))@iu',
'@</?((address)|(blockquote)|(center)|(del))@iu',
'@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
'@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
'@</?((table)|(th)|(td)|(caption))@iu',
'@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
'@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
'@</?((frameset)|(frame)|(iframe))@iu',
),
array(
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
"\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
"\n\$0", "\n\$0",
),
$text);
// Remove all remaining tags and comments and return.
echo strip_tags($text);
}
那麼,在哪裏調用'strip_html_tags($ your_text)'這是什麼結果呢?另外,你是否理解你向我們展示了一個函數定義?並沒有顯示函數調用? –
我忘了提及我不知道PHP ..我只是一個新手。要轉換成純文本的html頁面將成爲http://static.anaf.ro/static/10/Timis/Timis.htm問題中包含的鏈接,除此之外,我不知道應該包含哪些內容code..this實際上是我希望得到的幫助...一些dirrections至少 – user656931
然後,我建議你閱讀說明書 - http://php.net/manual/en/language.functions.php –