2016-09-28 13 views
0

サードパーティのAPIからデータを受け取ります。文字列からこの空白を取り除く

時にはデータが大きくなく、空白がたくさんあります。私は運なしLTRIM()、およびにpreg_replace()を使用して試した

$job['description'] = ltrim($job['description']); 
$job['description'] = preg_replace('/^\s+/S', " ", $job['description']); 

'空白' は、文字列の先頭に常にあります。以下は、レスポンスから直接コピーされたものです。

        Cover Supervisors 

これはまったく役に立ちます。どのようなアイデアを試して??

EDIT ::

のvar_dumpを示しています

string(1664) "Cover Supervisors 
Leicester & Surrounding areas 
£65 - £110 per day 
Required for the New Term 
Immediate Interviews 

Clarence Recruitment is currently looking for Cover Supervisors to work in Secondary schools across the Leicester area. 

• Do you have any experience of working with children 11-16yrs and have a good knowledge of the National Curriculum? 

• Are you looking to have a future within the education sector? 

• Would you like the freedom to choose the days you work? 

We are currently experiencing a high demand for flexible, part time and full time secondary cover supervisors. 

We are therefore looking to recruit temporary staff, ideally those who are looking to build a long term career in teaching and would like to gain further school based experience before starting a PGCE/SCITT or SD program. 

We are currently working with numerous vacancies so if this position is not quite for you please do send us your CV to discuss other opportunities more suitable to your requirements. 

Alan (your consultant) has been working the East Midlands Desk for over 5 years so his knowledge of the local schools is exceptional. He has also gained QTS so he knows the education system extremely well. Feel free to contact him for a more detailed chat about the roles we can help you fill. 

Clarence Recruitment is committed to safeguarding and promoting the welfare of children and young people and expects all staff and volunteers to share this commitment. The successful candidate will be required to have an enhanced DBS check in line with the Government’s Keeping Children Safe in Education guidelines (2014)" 
+1

'var_dump($ job ['description']); ' – AbraCadaver

+0

空白をタブにできませんでしたか?スペースではなくむしろ。スペースを削除しようとしていますが、実際にはタブがあります。 – masterFly

+0

再現不可、https://eval.in/652084; https://eval.in/652085。おそらく空白はエンティティですか? – chris85

答えて

0

それはおそらく浮気非改行スペースです。明示的に削除してください:

$job['description'] = str_replace(' ', '', preg_replace('/^\s+/S', ' ', $job['description']));

また、途中でhtmlentitiesを追加することができますが、それは許容できるのかどうかは、あなたが作業しているデータに依存しています。

関連する問題