Azteroth Posted May 29, 2008 Share Posted May 29, 2008 ok I am receiving a string from a database and on of the strings returns a & so my xml output is giving me the following error: Whitespace is not allowed at this location. Error processing resource I am wondering how to make this string if it contains the & replace it with & Thank you ahead for any help Link to comment https://forums.phpfreaks.com/topic/107851-remove/ Share on other sites More sharing options...
jonsjava Posted May 29, 2008 Share Posted May 29, 2008 use str_replace to replace the "&": $string = "bleh & bleh"; $new_string = str_replace("&", "&", $string"); Link to comment https://forums.phpfreaks.com/topic/107851-remove/#findComment-552860 Share on other sites More sharing options...
Azteroth Posted May 29, 2008 Author Share Posted May 29, 2008 thanks for the quick response but what happens if there is no & in the data that comes back... I just found something on using CDATA to have & in my data... problem is that it comes back with an error like this: Declaration has an invalid name It seems that I am having troubles with the xml that php is putting out... $xml_out = "<!CDATA[".$full_descRow['listingsdbelements_field_value']."]]>"; this is the line that is giving the error now:( Link to comment https://forums.phpfreaks.com/topic/107851-remove/#findComment-552887 Share on other sites More sharing options...
jonsjava Posted May 29, 2008 Share Posted May 29, 2008 erm...... string = "bleh & bleh"; $new_string = str_replace("& ", "&", $string"); now if the "&" is part of an & , it won't replace it. If that doesn't fix it, I don't know what to say. the only thing this does is converts & to & . If there isn't an "&" it does nothing to the code. Link to comment https://forums.phpfreaks.com/topic/107851-remove/#findComment-552895 Share on other sites More sharing options...
Azteroth Posted May 29, 2008 Author Share Posted May 29, 2008 ok so that works on the description string that is returned from my db... would this be an alright way to go about making sure my xml will work... $str = str_replace("&", "&", $misc_string); $final_str = str_replace("<", "<", &str); echo $str; because it will still register to $str if there is no & right? Link to comment https://forums.phpfreaks.com/topic/107851-remove/#findComment-552912 Share on other sites More sharing options...
Azteroth Posted May 29, 2008 Author Share Posted May 29, 2008 I figure this is true based on the fact that it is still displaying... lol. Anyway thanks for all your help in this problem jonsjava it is much appreciated Link to comment https://forums.phpfreaks.com/topic/107851-remove/#findComment-552929 Share on other sites More sharing options...
discomatt Posted May 29, 2008 Share Posted May 29, 2008 Use htmlentities(). Does all the replacing for you Link to comment https://forums.phpfreaks.com/topic/107851-remove/#findComment-552938 Share on other sites More sharing options...
Azteroth Posted May 29, 2008 Author Share Posted May 29, 2008 thank you I found that the other day when I ran into a problem and got rid of it... now I know that my database and my clients database aren't exactly the same... so it was sending back a character error... now I am just creating on my clients database so I shouldn't run into the same problem hopefully... thank you for your response discomatt. I have another question how would I take a string that comes back like: 0123456789 and make it display like: 123 456 789 this is for an Italian phone number but was stored on the database like the prior... but if the first character is not zero I want it to display it also... with the same sort of formatting... how can I do this Link to comment https://forums.phpfreaks.com/topic/107851-remove/#findComment-553001 Share on other sites More sharing options...
Azteroth Posted May 29, 2008 Author Share Posted May 29, 2008 just tried the htmlentities() and get the following error <listing_desc>La Divisione Ricerca & Selezione di MEN AT WORK - FILIALE DI ODERZO - sta cercando una persona da inserire in uno studio professionale ubicato a Oderzo; la/il candidata/o ideale dovrebbe possedere i seguenti requisiti: esperienza significativa nella tenuta della contabilità fino al bilancio contabile di chiusura con scritture di rettifica, autonomia nella gestione dei clienti e dello studio, diploma di ragioneria, preferibile esperienza precedente in studio professionale.</listing_desc> <listing_create_date>27/03/2008</listing_create_date> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^ so I think that sticking with what I have is the best bet Link to comment https://forums.phpfreaks.com/topic/107851-remove/#findComment-553005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.