In $variable I have html code which reads like:`PHP str_replace <tag>東西 - 東西</tag>納入<a href="stuff">Stuff<a href="things">Things?
<tag>Lots of Text Here - More Phrases Here</tag>.
I'd like to be able to str_replace the string in between the 2 tags
<tag> string </tag>
I want the new code to read:
<tag><a href="Lots">Lots</a> <a href="of">of</a>
<a href="text">Text</a> <a href="here">Here</a> -
<a href="@morephraseshere">@MorePhrasesHere</a></tag>
I know this might be a lot to str_replace all at once, but if you can at least get either the "Lots of Text Here" to become links, or if you can get the @MorePhrasesHere to become a link it would be amazing.
Or the closest you can get to a full solution would be fantastic as well.
The string of text in $variable changes for each entry. A preg_match or str_explode solution for $variable would be amazing as well if you can't do it in str_replace.
Thank you!
Edit: The objective is to turn every word in the first string into a #hashtag, and every word in the second string into a @username. The server knows how to return valid responses for both types of links.
它是否每次都從開始,最後有 ? –
splash58
是的,這兩個標籤是一致的,裏面的文字會一直改變。在兩個字符串之間總會有一個「 - 」:「 string - string2 –
你不能使用'str_replace',你不知道里面會有什麼,你可以使用'preg_replace'或'preg_match'。如果你使用'preg_match',你必須在後面建立與找到的值的鏈接。在你的例子中,'text'和'here'是如何鏈接的? – chris85