我试图从使用php curl的网站获得数据。从输出中,我需要忽略所有的空格和空行。我用了一些正则表达式。我真的不熟悉正则表达式。
请帮我解决这个问题。
这是我的代码:
if(preg_match('/<div class="search-results-details-body">(.*?) <div class="search-results-details-footer">/s', $result, $output))
{
$stripped_result = ltrim(strip_tags($output[1]));
$refined_output = str_replace(' ','',$stripped_result);
$regex = preg_replace('['n'n]', "'n", $refined_output); exit();
}
,这是我的输出顺序:
Requirements
Minimum 2 years of web development experience is required
Experience with PHP, MySQL, HTML, CSS, and JavaScript are preferred
Bachelors Degree in Computer Science or related field
Full knowledge and experience of software development lifecycle
Strong organisational and analytical skills
Ability to work under pressure to meet deadlines and required quality standards
Ability to multi-task and prioritize responsibilities
Excellent oral and written communication skills
这里我想删除所有开始的空白。我需要得到这样的输出:
Requirements
Minimum 2 years of web development experience is required
Experience with PHP, MySQL, HTML, CSS, and JavaScript are preferred
Bachelors Degree in Computer Science or related field
Full knowledge and experience of software development lifecycle
Strong organisational and analytical skills
Ability to work under pressure to meet deadlines and required quality standards
Ability to multi-task and prioritize responsibilities
Excellent oral and written communication skills
请提出一个好的解决方案
谢谢
我想删除所有开始的空白,我需要忽略所有的空白和空行。
用空字符串
替换^'s+
这是在线演示
-
^
匹配行/字符串的开头 -
's
匹配任何空白字符['r'n't'f ]
示例代码:
$re = "/^''s+/m";
$result = preg_replace($re, '', $str);